feat: remove serde flatten of reference limitation#33
Open
markhilb wants to merge 1 commit intokurtbuilds:masterfrom
Open
feat: remove serde flatten of reference limitation#33markhilb wants to merge 1 commit intokurtbuilds:masterfrom
markhilb wants to merge 1 commit intokurtbuilds:masterfrom
Conversation
Owner
|
It's been a while since I looked at this, but I believe the issue is the Baz schema that the reference refers to is never added to the spec. Maybe that's ok? Or it prints a warning? But silently creating an invalid spec feels wrong. |
Contributor
Author
|
I'm not sure which spec you mean. use actix_web::web::Json;
use oasgen::{OaSchema, Server, oasgen};
use serde::Serialize;
#[derive(OaSchema, Serialize)]
pub struct Baz {
value: i32,
}
#[derive(OaSchema, Serialize)]
pub struct Bar {
baz: Baz,
}
#[derive(OaSchema, Serialize)]
pub struct Foo {
#[serde(flatten)]
flattened: Bar,
}
#[oasgen]
async fn foo() -> Json<Foo> {
todo!()
}
fn main() {
let server = Server::actix().get("/foo", foo);
let schema = serde_yaml::to_string(&Foo::schema()).unwrap();
let spec = serde_yaml::to_string(&server.openapi).unwrap();
println!("{schema}");
println!();
println!("{spec}");
}type: object
properties:
baz:
$ref: '#/components/schemas/Baz'
required:
- baz
openapi: 3.0.3
info:
title: ''
version: ''
paths:
/foo:
get:
operationId: foo
responses:
'200':
description: ''
content:
application/json:
schema:
$ref: '#/components/schemas/Foo'
components:
schemas:
Bar:
type: object
properties:
baz:
$ref: '#/components/schemas/Baz'
required:
- baz
Baz:
type: object
properties:
value:
type: integer
required:
- value
Foo:
type: object
properties:
baz:
$ref: '#/components/schemas/Baz'
required:
- baz |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Don't see why this is a problem.
Correct me if i'm wrong.