-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve schema building, bug fixes #1012
Improve schema building, bug fixes #1012
Conversation
53f1e9e
to
48a4288
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's hard to understand what is fixed/changed. Can you keep the old tests as they are if modification is not needed and add new ones? Or please comment on every test change and describe why it changed. Thanks!
((MapSchema) petSchema.properties['freeForm']).description == "A free-form object" | ||
((MapSchema) petSchema.properties['freeForm']).getAdditionalProperties() == true | ||
petSchema.properties['freeForm'].type == "object" | ||
petSchema.properties['freeForm'].description == "A free-form object" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now we have just instance of Schema class
@@ -21,7 +21,7 @@ import io.swagger.v3.oas.annotations.Operation; | |||
class OpenApiController { | |||
|
|||
@Operation(summary = "Update tag", description = "Updates an existing tag", tags = "users_tag") | |||
@Post("/tags/{tagId: \\\\d+}/{path:.*}{.ext}/update{/id:[a-zA-Z]+}/{+path}{?max,offset}") | |||
@Post("/tags/{tagId: \\\\d+}/{path:.*}{.ext}/update/{+path}{?max,offset}{/id:[a-zA-Z]+}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optional path variable must be last
@Controller("/path") | ||
class OpenApiController { | ||
|
||
@Patch | ||
public HttpResponse<String> processSync4(@Parameter(schema = @Schema(type = "string", format = "uuid")) String param) { | ||
public HttpResponse<String> processSync4(@Parameter(schema = @Schema(type = "string", format = "uuid")) @QueryValue String param) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added lost annotation @QueryValue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We support no-annotation parameters, which can also be query value, but for proper OpenApi it might be needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dstepanov I didn't test it for Patch method, can tell you what I know:
- For Get method - it is true. And I've add support it in openapi
- For Post method, if you dont's set annotation, parameters are automatically treated as wrapped, i.e. they must be passed in the request body (by the way, I don’t understand at all why the logic is different for different methods. This is not at all obvious), or as path variables (it's supported too)
Which logic for other methods - I didn't test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this test before my changes in field in
was null value
return HttpResponse.ok(); | ||
} | ||
|
||
@Put | ||
public HttpResponse<String> processSync3( | ||
@Parameter(schema = @Schema(ref = "#/components/schemas/MyParamSchema")) Optional<Period> period) { | ||
@Parameter(schema = @Schema(ref = "#/components/schemas/MyParamSchema")) @QueryValue Optional<Period> period) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added lost @QueryValue
annotation
String test7(String someId, @Nullable String someNotRequired, java.util.Optional<String> someNotRequired2, HttpRequest req, Principal principal, @Body Greeting myBody); | ||
|
||
@Get("/test8{/pathVar1,pathVar2}") | ||
String test8(String pathVar1, String pathVar2, String queryVar, @Nullable String name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new test case for optional path vars
@@ -918,7 +899,6 @@ class MyBean {} | |||
''') | |||
then: "the state is correct" | |||
!Utils.testReference | |||
!Utils.testReferenceAfterPlaceholders |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Utils.testReferenceAfterPlaceholders - this filed deleted and we need to check testReference always
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
public class MyJaxbElement4 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Schema(oneOf = {DiscountSizeOpenApi.class, DiscountFixedOpenApi.class, MultiplierSizeOpenApi.class})
Test for this block. Fixed processing in this PR
@@ -84,7 +83,6 @@ class MyBean {} | |||
then: | |||
openAPI.components.schemas | |||
openAPI.components.schemas.size() == 1 | |||
openAPI.components.schemas['Person'].name == 'Person' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
schema name always null. Schema name contains in schemas map
@@ -36,7 +36,7 @@ class OpenApiController { | |||
description = "This is description", | |||
tags = "Normalize", | |||
responses = { | |||
@ApiResponse(responseCode = "200", description = "Desc1", content = @Content(mediaType = MediaType.ALL, schema = @Schema(type = "blob", format = "binary"))), | |||
@ApiResponse(responseCode = "200", description = "Desc1", content = @Content(mediaType = MediaType.ALL, schema = @Schema(type = "string", format = "binary"))), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can't use custom values for type field
@@ -35,6 +35,7 @@ class MyDto { | |||
private JAXBElement<? extends XmlElement> xmlElement; | |||
private JAXBElement<? extends XmlElement2> xmlElement2; | |||
public JAXBElement<? extends XmlElement3> xmlElement3; | |||
public JAXBElement<? extends XmlElement4> xmlElement4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new test case for oneOf block
@dstepanov added comments to most of changes in tests. Need to double check to places (without comments now, I don't remember why I did these changes). You can check places with comments |
withRef.openIdConnectUrl == null | ||
withRef.bearerFormat == null | ||
withRef.flows == null | ||
withRef.scheme == null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this deleted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@graemerocher Because the swagger doesn't really support links to other security schemes. Therefore, when you try to deserialize a swagger file with such a scheme, it will be ignored, because. type is not specified. See class SecuritySchemeDeserializer:
That is, this test case is not correct.
48a4288
to
061f1ce
Compare
Main changes:
"/test{/pathVar1,pathVar2}"
)path
in all cases,query
for get requests)Code changes
postProcessOpenApi