forked from loafle/openapi-generator-original
[core] Add type and format properties to model of inline response (#6153)
This commit is contained in:
@@ -621,6 +621,15 @@ public class InlineModelResolver {
|
||||
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());
|
||||
|
||||
@@ -263,6 +263,23 @@ public class InlineModelResolverTest {
|
||||
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();
|
||||
|
||||
@@ -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]
|
||||
@@ -2090,10 +2090,12 @@ components:
|
||||
properties:
|
||||
breed:
|
||||
type: string
|
||||
type: object
|
||||
Cat_allOf:
|
||||
properties:
|
||||
declawed:
|
||||
type: boolean
|
||||
type: object
|
||||
BigCat_allOf:
|
||||
properties:
|
||||
kind:
|
||||
@@ -2103,6 +2105,7 @@ components:
|
||||
- leopards
|
||||
- jaguars
|
||||
type: string
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
flows:
|
||||
|
||||
@@ -2090,10 +2090,12 @@ components:
|
||||
properties:
|
||||
breed:
|
||||
type: string
|
||||
type: object
|
||||
Cat_allOf:
|
||||
properties:
|
||||
declawed:
|
||||
type: boolean
|
||||
type: object
|
||||
BigCat_allOf:
|
||||
properties:
|
||||
kind:
|
||||
@@ -2103,6 +2105,7 @@ components:
|
||||
- leopards
|
||||
- jaguars
|
||||
type: string
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
flows:
|
||||
|
||||
@@ -2090,10 +2090,12 @@ components:
|
||||
properties:
|
||||
breed:
|
||||
type: string
|
||||
type: object
|
||||
Cat_allOf:
|
||||
properties:
|
||||
declawed:
|
||||
type: boolean
|
||||
type: object
|
||||
BigCat_allOf:
|
||||
properties:
|
||||
kind:
|
||||
@@ -2103,6 +2105,7 @@ components:
|
||||
- leopards
|
||||
- jaguars
|
||||
type: string
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
flows:
|
||||
|
||||
@@ -2090,10 +2090,12 @@ components:
|
||||
properties:
|
||||
breed:
|
||||
type: string
|
||||
type: object
|
||||
Cat_allOf:
|
||||
properties:
|
||||
declawed:
|
||||
type: boolean
|
||||
type: object
|
||||
BigCat_allOf:
|
||||
properties:
|
||||
kind:
|
||||
@@ -2103,6 +2105,7 @@ components:
|
||||
- leopards
|
||||
- jaguars
|
||||
type: string
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
flows:
|
||||
|
||||
@@ -2151,10 +2151,12 @@ components:
|
||||
properties:
|
||||
breed:
|
||||
type: string
|
||||
type: object
|
||||
Cat_allOf:
|
||||
properties:
|
||||
declawed:
|
||||
type: boolean
|
||||
type: object
|
||||
BigCat_allOf:
|
||||
properties:
|
||||
kind:
|
||||
@@ -2164,6 +2166,7 @@ components:
|
||||
- leopards
|
||||
- jaguars
|
||||
type: string
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
flows:
|
||||
|
||||
@@ -2151,10 +2151,12 @@ components:
|
||||
properties:
|
||||
breed:
|
||||
type: string
|
||||
type: object
|
||||
Cat_allOf:
|
||||
properties:
|
||||
declawed:
|
||||
type: boolean
|
||||
type: object
|
||||
BigCat_allOf:
|
||||
properties:
|
||||
kind:
|
||||
@@ -2164,6 +2166,7 @@ components:
|
||||
- leopards
|
||||
- jaguars
|
||||
type: string
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
flows:
|
||||
|
||||
@@ -2151,10 +2151,12 @@ components:
|
||||
properties:
|
||||
breed:
|
||||
type: string
|
||||
type: object
|
||||
Cat_allOf:
|
||||
properties:
|
||||
declawed:
|
||||
type: boolean
|
||||
type: object
|
||||
BigCat_allOf:
|
||||
properties:
|
||||
kind:
|
||||
@@ -2164,6 +2166,7 @@ components:
|
||||
- leopards
|
||||
- jaguars
|
||||
type: string
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
flows:
|
||||
|
||||
@@ -2151,10 +2151,12 @@ components:
|
||||
properties:
|
||||
breed:
|
||||
type: string
|
||||
type: object
|
||||
Cat_allOf:
|
||||
properties:
|
||||
declawed:
|
||||
type: boolean
|
||||
type: object
|
||||
BigCat_allOf:
|
||||
properties:
|
||||
kind:
|
||||
@@ -2164,6 +2166,7 @@ components:
|
||||
- leopards
|
||||
- jaguars
|
||||
type: string
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
flows:
|
||||
|
||||
@@ -2151,10 +2151,12 @@ components:
|
||||
properties:
|
||||
breed:
|
||||
type: string
|
||||
type: object
|
||||
Cat_allOf:
|
||||
properties:
|
||||
declawed:
|
||||
type: boolean
|
||||
type: object
|
||||
BigCat_allOf:
|
||||
properties:
|
||||
kind:
|
||||
@@ -2164,6 +2166,7 @@ components:
|
||||
- leopards
|
||||
- jaguars
|
||||
type: string
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
flows:
|
||||
|
||||
@@ -2151,10 +2151,12 @@ components:
|
||||
properties:
|
||||
breed:
|
||||
type: string
|
||||
type: object
|
||||
Cat_allOf:
|
||||
properties:
|
||||
declawed:
|
||||
type: boolean
|
||||
type: object
|
||||
BigCat_allOf:
|
||||
properties:
|
||||
kind:
|
||||
@@ -2164,6 +2166,7 @@ components:
|
||||
- leopards
|
||||
- jaguars
|
||||
type: string
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
flows:
|
||||
|
||||
@@ -2151,10 +2151,12 @@ components:
|
||||
properties:
|
||||
breed:
|
||||
type: string
|
||||
type: object
|
||||
Cat_allOf:
|
||||
properties:
|
||||
declawed:
|
||||
type: boolean
|
||||
type: object
|
||||
BigCat_allOf:
|
||||
properties:
|
||||
kind:
|
||||
@@ -2164,6 +2166,7 @@ components:
|
||||
- leopards
|
||||
- jaguars
|
||||
type: string
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
flows:
|
||||
|
||||
@@ -2151,10 +2151,12 @@ components:
|
||||
properties:
|
||||
breed:
|
||||
type: string
|
||||
type: object
|
||||
Cat_allOf:
|
||||
properties:
|
||||
declawed:
|
||||
type: boolean
|
||||
type: object
|
||||
BigCat_allOf:
|
||||
properties:
|
||||
kind:
|
||||
@@ -2164,6 +2166,7 @@ components:
|
||||
- leopards
|
||||
- jaguars
|
||||
type: string
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
flows:
|
||||
|
||||
@@ -2151,10 +2151,12 @@ components:
|
||||
properties:
|
||||
breed:
|
||||
type: string
|
||||
type: object
|
||||
Cat_allOf:
|
||||
properties:
|
||||
declawed:
|
||||
type: boolean
|
||||
type: object
|
||||
BigCat_allOf:
|
||||
properties:
|
||||
kind:
|
||||
@@ -2164,6 +2166,7 @@ components:
|
||||
- leopards
|
||||
- jaguars
|
||||
type: string
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
flows:
|
||||
|
||||
@@ -2151,10 +2151,12 @@ components:
|
||||
properties:
|
||||
breed:
|
||||
type: string
|
||||
type: object
|
||||
Cat_allOf:
|
||||
properties:
|
||||
declawed:
|
||||
type: boolean
|
||||
type: object
|
||||
BigCat_allOf:
|
||||
properties:
|
||||
kind:
|
||||
@@ -2164,6 +2166,7 @@ components:
|
||||
- leopards
|
||||
- jaguars
|
||||
type: string
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
flows:
|
||||
|
||||
@@ -2151,10 +2151,12 @@ components:
|
||||
properties:
|
||||
breed:
|
||||
type: string
|
||||
type: object
|
||||
Cat_allOf:
|
||||
properties:
|
||||
declawed:
|
||||
type: boolean
|
||||
type: object
|
||||
BigCat_allOf:
|
||||
properties:
|
||||
kind:
|
||||
@@ -2164,6 +2166,7 @@ components:
|
||||
- leopards
|
||||
- jaguars
|
||||
type: string
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
flows:
|
||||
|
||||
@@ -2151,10 +2151,12 @@ components:
|
||||
properties:
|
||||
breed:
|
||||
type: string
|
||||
type: object
|
||||
Cat_allOf:
|
||||
properties:
|
||||
declawed:
|
||||
type: boolean
|
||||
type: object
|
||||
BigCat_allOf:
|
||||
properties:
|
||||
kind:
|
||||
@@ -2164,6 +2166,7 @@ components:
|
||||
- leopards
|
||||
- jaguars
|
||||
type: string
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
flows:
|
||||
|
||||
@@ -2151,10 +2151,12 @@ components:
|
||||
properties:
|
||||
breed:
|
||||
type: string
|
||||
type: object
|
||||
Cat_allOf:
|
||||
properties:
|
||||
declawed:
|
||||
type: boolean
|
||||
type: object
|
||||
BigCat_allOf:
|
||||
properties:
|
||||
kind:
|
||||
@@ -2164,6 +2166,7 @@ components:
|
||||
- leopards
|
||||
- jaguars
|
||||
type: string
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
flows:
|
||||
|
||||
@@ -2151,10 +2151,12 @@ components:
|
||||
properties:
|
||||
breed:
|
||||
type: string
|
||||
type: object
|
||||
Cat_allOf:
|
||||
properties:
|
||||
declawed:
|
||||
type: boolean
|
||||
type: object
|
||||
BigCat_allOf:
|
||||
properties:
|
||||
kind:
|
||||
@@ -2164,6 +2166,7 @@ components:
|
||||
- leopards
|
||||
- jaguars
|
||||
type: string
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
flows:
|
||||
|
||||
@@ -2151,10 +2151,12 @@ components:
|
||||
properties:
|
||||
breed:
|
||||
type: string
|
||||
type: object
|
||||
Cat_allOf:
|
||||
properties:
|
||||
declawed:
|
||||
type: boolean
|
||||
type: object
|
||||
BigCat_allOf:
|
||||
properties:
|
||||
kind:
|
||||
@@ -2164,6 +2166,7 @@ components:
|
||||
- leopards
|
||||
- jaguars
|
||||
type: string
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
flows:
|
||||
|
||||
@@ -2151,10 +2151,12 @@ components:
|
||||
properties:
|
||||
breed:
|
||||
type: string
|
||||
type: object
|
||||
Cat_allOf:
|
||||
properties:
|
||||
declawed:
|
||||
type: boolean
|
||||
type: object
|
||||
BigCat_allOf:
|
||||
properties:
|
||||
kind:
|
||||
@@ -2164,6 +2166,7 @@ components:
|
||||
- leopards
|
||||
- jaguars
|
||||
type: string
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
flows:
|
||||
|
||||
@@ -2151,10 +2151,12 @@ components:
|
||||
properties:
|
||||
breed:
|
||||
type: string
|
||||
type: object
|
||||
Cat_allOf:
|
||||
properties:
|
||||
declawed:
|
||||
type: boolean
|
||||
type: object
|
||||
BigCat_allOf:
|
||||
properties:
|
||||
kind:
|
||||
@@ -2164,6 +2166,7 @@ components:
|
||||
- leopards
|
||||
- jaguars
|
||||
type: string
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
flows:
|
||||
|
||||
@@ -2151,10 +2151,12 @@ components:
|
||||
properties:
|
||||
breed:
|
||||
type: string
|
||||
type: object
|
||||
Cat_allOf:
|
||||
properties:
|
||||
declawed:
|
||||
type: boolean
|
||||
type: object
|
||||
BigCat_allOf:
|
||||
properties:
|
||||
kind:
|
||||
@@ -2164,6 +2166,7 @@ components:
|
||||
- leopards
|
||||
- jaguars
|
||||
type: string
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
flows:
|
||||
|
||||
@@ -2151,10 +2151,12 @@ components:
|
||||
properties:
|
||||
breed:
|
||||
type: string
|
||||
type: object
|
||||
Cat_allOf:
|
||||
properties:
|
||||
declawed:
|
||||
type: boolean
|
||||
type: object
|
||||
BigCat_allOf:
|
||||
properties:
|
||||
kind:
|
||||
@@ -2164,6 +2166,7 @@ components:
|
||||
- leopards
|
||||
- jaguars
|
||||
type: string
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
flows:
|
||||
|
||||
@@ -1999,6 +1999,7 @@ components:
|
||||
properties:
|
||||
string:
|
||||
$ref: '#/components/schemas/Foo'
|
||||
type: object
|
||||
inline_object:
|
||||
properties:
|
||||
name:
|
||||
@@ -2138,10 +2139,12 @@ components:
|
||||
properties:
|
||||
breed:
|
||||
type: string
|
||||
type: object
|
||||
Cat_allOf:
|
||||
properties:
|
||||
declawed:
|
||||
type: boolean
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
flows:
|
||||
|
||||
@@ -1920,6 +1920,7 @@ components:
|
||||
properties:
|
||||
string:
|
||||
$ref: '#/components/schemas/Foo'
|
||||
type: object
|
||||
inline_object:
|
||||
properties:
|
||||
name:
|
||||
@@ -2059,10 +2060,12 @@ components:
|
||||
properties:
|
||||
breed:
|
||||
type: string
|
||||
type: object
|
||||
Cat_allOf:
|
||||
properties:
|
||||
declawed:
|
||||
type: boolean
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
flows:
|
||||
|
||||
@@ -2249,6 +2249,7 @@ components:
|
||||
properties:
|
||||
string:
|
||||
$ref: '#/components/schemas/Foo'
|
||||
type: object
|
||||
inline_object:
|
||||
properties:
|
||||
name:
|
||||
@@ -2390,14 +2391,17 @@ components:
|
||||
properties:
|
||||
breed:
|
||||
type: string
|
||||
type: object
|
||||
Cat_allOf:
|
||||
properties:
|
||||
declawed:
|
||||
type: boolean
|
||||
type: object
|
||||
ChildCat_allOf:
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
flows:
|
||||
|
||||
@@ -2831,14 +2831,16 @@
|
||||
"breed" : {
|
||||
"type" : "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"type" : "object"
|
||||
},
|
||||
"Cat_allOf" : {
|
||||
"properties" : {
|
||||
"declawed" : {
|
||||
"type" : "boolean"
|
||||
}
|
||||
}
|
||||
},
|
||||
"type" : "object"
|
||||
},
|
||||
"BigCat_allOf" : {
|
||||
"properties" : {
|
||||
@@ -2846,7 +2848,8 @@
|
||||
"enum" : [ "lions", "tigers", "leopards", "jaguars" ],
|
||||
"type" : "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"type" : "object"
|
||||
}
|
||||
},
|
||||
"securitySchemes" : {
|
||||
|
||||
@@ -2225,10 +2225,12 @@ components:
|
||||
properties:
|
||||
breed:
|
||||
type: string
|
||||
type: object
|
||||
Cat_allOf:
|
||||
properties:
|
||||
declawed:
|
||||
type: boolean
|
||||
type: object
|
||||
BigCat_allOf:
|
||||
properties:
|
||||
kind:
|
||||
@@ -2238,6 +2240,7 @@ components:
|
||||
- leopards
|
||||
- jaguars
|
||||
type: string
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
flows:
|
||||
|
||||
@@ -2225,10 +2225,12 @@ components:
|
||||
properties:
|
||||
breed:
|
||||
type: string
|
||||
type: object
|
||||
Cat_allOf:
|
||||
properties:
|
||||
declawed:
|
||||
type: boolean
|
||||
type: object
|
||||
BigCat_allOf:
|
||||
properties:
|
||||
kind:
|
||||
@@ -2238,6 +2240,7 @@ components:
|
||||
- leopards
|
||||
- jaguars
|
||||
type: string
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
flows:
|
||||
|
||||
@@ -132,4 +132,5 @@ components:
|
||||
type: array
|
||||
required:
|
||||
- field_a
|
||||
type: object
|
||||
|
||||
|
||||
@@ -606,6 +606,7 @@ components:
|
||||
properties:
|
||||
foo:
|
||||
type: string
|
||||
type: object
|
||||
securitySchemes:
|
||||
authScheme:
|
||||
flows:
|
||||
|
||||
@@ -1565,10 +1565,12 @@ components:
|
||||
properties:
|
||||
breed:
|
||||
type: string
|
||||
type: object
|
||||
Cat_allOf:
|
||||
properties:
|
||||
declawed:
|
||||
type: boolean
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
flows:
|
||||
|
||||
@@ -211,4 +211,5 @@ components:
|
||||
type: integer
|
||||
required:
|
||||
- required_thing
|
||||
type: object
|
||||
|
||||
|
||||
@@ -2225,10 +2225,12 @@ components:
|
||||
properties:
|
||||
breed:
|
||||
type: string
|
||||
type: object
|
||||
Cat_allOf:
|
||||
properties:
|
||||
declawed:
|
||||
type: boolean
|
||||
type: object
|
||||
BigCat_allOf:
|
||||
properties:
|
||||
kind:
|
||||
@@ -2238,6 +2240,7 @@ components:
|
||||
- leopards
|
||||
- jaguars
|
||||
type: string
|
||||
type: object
|
||||
securitySchemes:
|
||||
petstore_auth:
|
||||
flows:
|
||||
|
||||
Reference in New Issue
Block a user