Java Code Examples for io.swagger.v3.oas.models.media.ObjectSchema#setTitle()
The following examples show how to use
io.swagger.v3.oas.models.media.ObjectSchema#setTitle() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InlineModelResolverTest.java From swagger-parser with Apache License 2.0 | 5 votes |
@Test public void testArbitraryObjectModelInline() { OpenAPI openAPI = new OpenAPI(); openAPI.setComponents(new Components()); Schema userSchema = new Schema(); userSchema.setName("user"); userSchema.setDescription("a common user"); userSchema.addProperties("name", new StringSchema()); ObjectSchema objectSchema = new ObjectSchema(); objectSchema.setTitle("title"); objectSchema.setDefault("default"); objectSchema.setReadOnly(false); objectSchema.setDescription("description"); objectSchema.setName("name"); userSchema.addProperties("arbitrary", objectSchema); List required = new ArrayList(); required.add("arbitrary"); userSchema.setRequired(required); openAPI.getComponents().addSchemas("User", userSchema); new InlineModelResolver().flatten(openAPI); Schema user = openAPI.getComponents().getSchemas().get("User"); assertNotNull(user); Schema inlineProp = (Schema) user.getProperties().get("arbitrary"); assertTrue(inlineProp instanceof ObjectSchema); assertNull(inlineProp.getProperties()); }
Example 2
Source File: InlineModelResolverTest.java From swagger-parser with Apache License 2.0 | 2 votes |
@Test public void testInlineResponseModelWithTitle() throws Exception { OpenAPI openAPI = new OpenAPI(); String responseTitle = "GetBarResponse"; StringSchema stringSchema1 = new StringSchema(); ObjectSchema objectSchema1 = new ObjectSchema(); objectSchema1.setTitle(responseTitle); objectSchema1.addProperties("name", stringSchema1); MediaType mediaType1 = new MediaType(); mediaType1.setSchema(objectSchema1); Content content1 = new Content(); content1.addMediaType("*/*", mediaType1 ); ApiResponse response1= new ApiResponse(); response1.setDescription("it works!"); response1.setContent(content1); ApiResponses responses1 = new ApiResponses(); responses1.addApiResponse("200",response1); Operation operation1 = new Operation(); operation1.setResponses(responses1); PathItem pathItem1 = new PathItem(); pathItem1.setGet(operation1); openAPI.path("/foo/bar",pathItem1); StringSchema stringSchema2 = new StringSchema(); ObjectSchema objectSchema2 = new ObjectSchema(); objectSchema2.addProperties("name", stringSchema2); objectSchema2.addExtension("x-foo", "bar"); MediaType mediaType2 = new MediaType(); mediaType2.setSchema(objectSchema2); Content content2 = new Content(); content2.addMediaType("*/*", mediaType2 ); ApiResponse response2 = new ApiResponse(); response2.setDescription("it works!"); response2.setContent(content2); ApiResponses responses2 = new ApiResponses(); responses2.addApiResponse("200",response2); Operation operation2 = new Operation(); operation2.setResponses(responses2); PathItem pathItem2 = new PathItem(); pathItem2.setGet(operation2); openAPI.path("/foo/baz",pathItem2); new InlineModelResolver().flatten(openAPI); Map<String, ApiResponse> responses = openAPI.getPaths().get("/foo/bar").getGet().getResponses(); ApiResponse response = responses.get("200"); assertNotNull(response); assertTrue(response.getContent().get("*/*").getSchema().get$ref() != null ); Schema model = openAPI.getComponents().getSchemas().get(responseTitle); assertTrue(model.getProperties().size() == 1); assertNotNull(model.getProperties().get("name")); assertTrue(model.getProperties().get("name") instanceof StringSchema); }