Skip to content

Commit

Permalink
[core] Add type and format properties to model of inline response (#6153
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ybelenko authored Aug 3, 2020
1 parent 1be98b4 commit 6a08ec5
Show file tree
Hide file tree
Showing 37 changed files with 204 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,15 @@ private Schema modelFromProperty(OpenAPI openAPI, Schema object, String path) {
XML xml = object.getXml();
Map<String, Schema> properties = object.getProperties();
Schema model = new Schema();
if (object.getType() != null) {
model.setType(object.getType());
}
if (object.getFormat() != null) {
// Even though the `format` keyword typically applies to primitive types only,
// the JSON schema specification states `format` can be used for any model type instance
// including object types.
model.setFormat(object.getFormat());
}
model.setDescription(description);
model.setExample(example);
model.setName(object.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,23 @@ public void testInlineResponseModel() {
assertTrue(model.getProperties().get("name") instanceof StringSchema);
}

@Test
public void testInlineResponseModelType() {
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/6150_model_json_inline.yaml");
new InlineModelResolver().flatten(openAPI);

Schema InlineResponse200 = openAPI.getComponents().getSchemas().get("inline_response_200");
assertEquals("object", InlineResponse200.getType());
assertEquals("unknown", InlineResponse200.getFormat());
Schema FooBarObject = openAPI.getComponents().getSchemas().get("FooBarObject");
assertEquals("object", FooBarObject.getType());
assertEquals("date-time", FooBarObject.getFormat());
Schema Animal = openAPI.getComponents().getSchemas().get("Animal");
assertEquals("object", Animal.getType());
Schema Dog = openAPI.getComponents().getSchemas().get("Dog");
assertNull(Dog.getType());
}

@Test
public void testInlineResponseModelWithTitle() {
OpenAPI openapi = new OpenAPI();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
openapi: "3.0.0"
info:
version: 1.0.0
title: Test inline response model
description: Test inline response model.
license:
name: MIT
paths:
/foobar:
get:
operationId: testOperation
description: No type property in modelJson of InlineResponse200
responses:
200:
description: InlineResponse200 itself.
content:
application/json:
schema:
type: object
# It is legal to use the `format` keyword for object types. The JSON schema specification explicitly allows this.
# Even if in practice most OAS authors use `format` for primitive types, it should still be allowed to use format for object types.
format: unknown
properties:
foo:
type: string
bar:
type: string
post:
operationId: testOperationPost
description: No type property in modelJson of InlineResponse200
responses:
400:
description: InlineResponse200 itself.
content:
application/json:
schema:
title: FooBarObject
type: object
# It is legal to use the `format` keyword for object types. The JSON schema specification explicitly allows this.
# Even if in practice most OAS authors use `format` for primitive types, it should still be allowed to use format for object types.
format: date-time
properties:
foo:
type: string
components:
schemas:
Animal:
type: object
discriminator: className
required:
- className
properties:
className:
type: string
color:
type: string
default: 'red'
Dog:
allOf:
- $ref: '#/components/schemas/Animal'
- type: object
properties:
breed:
type: string
Cat:
allOf:
- $ref: '#/components/schemas/Animal'
- type: object
properties:
declawed:
type: boolean
HugeCat:
allOf:
- $ref: '#/components/schemas/Cat'
- type: object
properties:
kind:
type: string
enum: [lions, tigers, leopards, jaguars]
Original file line number Diff line number Diff line change
Expand Up @@ -2090,10 +2090,12 @@ components:
properties:
breed:
type: string
type: object
Cat_allOf:
properties:
declawed:
type: boolean
type: object
BigCat_allOf:
properties:
kind:
Expand All @@ -2103,6 +2105,7 @@ components:
- leopards
- jaguars
type: string
type: object
securitySchemes:
petstore_auth:
flows:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2090,10 +2090,12 @@ components:
properties:
breed:
type: string
type: object
Cat_allOf:
properties:
declawed:
type: boolean
type: object
BigCat_allOf:
properties:
kind:
Expand All @@ -2103,6 +2105,7 @@ components:
- leopards
- jaguars
type: string
type: object
securitySchemes:
petstore_auth:
flows:
Expand Down
3 changes: 3 additions & 0 deletions samples/client/petstore/go/go-petstore/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2090,10 +2090,12 @@ components:
properties:
breed:
type: string
type: object
Cat_allOf:
properties:
declawed:
type: boolean
type: object
BigCat_allOf:
properties:
kind:
Expand All @@ -2103,6 +2105,7 @@ components:
- leopards
- jaguars
type: string
type: object
securitySchemes:
petstore_auth:
flows:
Expand Down
3 changes: 3 additions & 0 deletions samples/client/petstore/haskell-http-client/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2090,10 +2090,12 @@ components:
properties:
breed:
type: string
type: object
Cat_allOf:
properties:
declawed:
type: boolean
type: object
BigCat_allOf:
properties:
kind:
Expand All @@ -2103,6 +2105,7 @@ components:
- leopards
- jaguars
type: string
type: object
securitySchemes:
petstore_auth:
flows:
Expand Down
3 changes: 3 additions & 0 deletions samples/client/petstore/java/feign/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2151,10 +2151,12 @@ components:
properties:
breed:
type: string
type: object
Cat_allOf:
properties:
declawed:
type: boolean
type: object
BigCat_allOf:
properties:
kind:
Expand All @@ -2164,6 +2166,7 @@ components:
- leopards
- jaguars
type: string
type: object
securitySchemes:
petstore_auth:
flows:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2151,10 +2151,12 @@ components:
properties:
breed:
type: string
type: object
Cat_allOf:
properties:
declawed:
type: boolean
type: object
BigCat_allOf:
properties:
kind:
Expand All @@ -2164,6 +2166,7 @@ components:
- leopards
- jaguars
type: string
type: object
securitySchemes:
petstore_auth:
flows:
Expand Down
3 changes: 3 additions & 0 deletions samples/client/petstore/java/jersey1/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2151,10 +2151,12 @@ components:
properties:
breed:
type: string
type: object
Cat_allOf:
properties:
declawed:
type: boolean
type: object
BigCat_allOf:
properties:
kind:
Expand All @@ -2164,6 +2166,7 @@ components:
- leopards
- jaguars
type: string
type: object
securitySchemes:
petstore_auth:
flows:
Expand Down
3 changes: 3 additions & 0 deletions samples/client/petstore/java/jersey2-java8/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2151,10 +2151,12 @@ components:
properties:
breed:
type: string
type: object
Cat_allOf:
properties:
declawed:
type: boolean
type: object
BigCat_allOf:
properties:
kind:
Expand All @@ -2164,6 +2166,7 @@ components:
- leopards
- jaguars
type: string
type: object
securitySchemes:
petstore_auth:
flows:
Expand Down
3 changes: 3 additions & 0 deletions samples/client/petstore/java/native-async/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2151,10 +2151,12 @@ components:
properties:
breed:
type: string
type: object
Cat_allOf:
properties:
declawed:
type: boolean
type: object
BigCat_allOf:
properties:
kind:
Expand All @@ -2164,6 +2166,7 @@ components:
- leopards
- jaguars
type: string
type: object
securitySchemes:
petstore_auth:
flows:
Expand Down
3 changes: 3 additions & 0 deletions samples/client/petstore/java/native/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2151,10 +2151,12 @@ components:
properties:
breed:
type: string
type: object
Cat_allOf:
properties:
declawed:
type: boolean
type: object
BigCat_allOf:
properties:
kind:
Expand All @@ -2164,6 +2166,7 @@ components:
- leopards
- jaguars
type: string
type: object
securitySchemes:
petstore_auth:
flows:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2151,10 +2151,12 @@ components:
properties:
breed:
type: string
type: object
Cat_allOf:
properties:
declawed:
type: boolean
type: object
BigCat_allOf:
properties:
kind:
Expand All @@ -2164,6 +2166,7 @@ components:
- leopards
- jaguars
type: string
type: object
securitySchemes:
petstore_auth:
flows:
Expand Down
3 changes: 3 additions & 0 deletions samples/client/petstore/java/okhttp-gson/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2151,10 +2151,12 @@ components:
properties:
breed:
type: string
type: object
Cat_allOf:
properties:
declawed:
type: boolean
type: object
BigCat_allOf:
properties:
kind:
Expand All @@ -2164,6 +2166,7 @@ components:
- leopards
- jaguars
type: string
type: object
securitySchemes:
petstore_auth:
flows:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2151,10 +2151,12 @@ components:
properties:
breed:
type: string
type: object
Cat_allOf:
properties:
declawed:
type: boolean
type: object
BigCat_allOf:
properties:
kind:
Expand All @@ -2164,6 +2166,7 @@ components:
- leopards
- jaguars
type: string
type: object
securitySchemes:
petstore_auth:
flows:
Expand Down
Loading

0 comments on commit 6a08ec5

Please sign in to comment.