Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/test/java/io/swagger/oas/test/examples/ExampleBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@
import io.swagger.v3.parser.OpenAPIV3Parser;
import io.swagger.v3.parser.core.models.AuthorizationValue;
import io.swagger.v3.parser.core.models.ParseOptions;
import io.swagger.v3.parser.core.models.SwaggerParseResult;
import mockit.Injectable;
import org.apache.commons.io.FileUtils;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -1058,4 +1061,39 @@ public void testNullExampleSupportOAS3NoFlag() throws Exception{
output = Json.pretty(example);
assertEquals(output, "[ \"foo\", " + null + " ]");
}

@Test
public void testAllOfMergeSchemas() throws Exception {
String expected = "{\n" +
" \"data\" : [ {\n" +
" \"topApiId\" : \"8ab9b11d-bf43-469e-a276-f601801d043c\",\n" +
" \"name\" : \"docman\",\n" +
" \"pathwaysVersion\" : \"0.1\",\n" +
" \"active\" : false,\n" +
" \"created\" : \"2018-07-21T17:32:28Z\"\n" +
" }, {\n" +
" \"topApiId\" : \"baa0dc91-9711-4b61-9c90-ce8ac0b109a9\",\n" +
" \"name\" : \"careweb\",\n" +
" \"pathwaysVersion\" : \"0.1\",\n" +
" \"active\" : true,\n" +
" \"created\" : \"2019-07-21T17:32:28Z\"\n" +
" } ],\n" +
" \"pagination\" : {\n" +
" \"offset\" : 0,\n" +
" \"limit\" : 10,\n" +
" \"totalResultCount\" : 100\n" +
" }\n" +
"}";
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setResolveFully(true);
options.setResolveCombinators(false);
String pathFile = FileUtils.readFileToString(new File("./src/test/swagger/issue-22849.yaml"), "UTF-8");
SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readContents(pathFile, null, options);
OpenAPI openAPI = swaggerParseResult.getOpenAPI();
ApiResponse response = openAPI.getPaths().get("/topApis").getGet().getResponses().get("200");

Example example = ExampleBuilder.fromSchema(response.getContent().get("application/json").getSchema(), null, ExampleBuilder.RequestType.READ);
assertEquals(Json.pretty(example),expected);
}
}
127 changes: 127 additions & 0 deletions src/test/swagger/issue-22849.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
openapi: 3.0.0
info:
version: "minimal-repro"
title: TopApis API
paths:
"/topApis":
get:
tags:
- TopApi
summary: List TopApis
operationId: listTopApis
parameters:
- in: query
name: includeInactive
schema:
type: boolean
required: false
example: false
- in: query
name: filterByName
schema:
type: string
required: false
example: 'ada'
- in: query
name: offset
schema:
type: integer
minimum: 0
default: 0
required: false
example: 5
- in: query
name: limit
schema:
type: integer
minimum: 1
default: 10
required: false
example: 10
responses:
'200':
description: a description
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/ListOfTopApis'
- $ref: '#/components/schemas/Pagination'
components:
schemas:
TopApi:
type: object
required:
- name
- pathwaysVersion
additionalProperties: false
properties:
topApiId:
type: string
format: uuid
readOnly: true
example: '884c0363-bbbe-4a5e-8d4f-1d34910803fc'
name:
type: string
example: 'adastra'
pathwaysVersion:
type: string
example: '0.1'
active:
type: boolean
readOnly: true
example: true
created:
type: string
format: date-time
readOnly: true
example: '2017-07-21T17:32:28Z'
ListOfTopApis:
type: object
additionalProperties: false
properties:
data:
type: array
items:
$ref: '#/components/schemas/TopApi'
example:
data:
- topApiId: '8ab9b11d-bf43-469e-a276-f601801d043c'
name: 'docman'
pathwaysVersion: '0.1'
active: false
created: '2018-07-21T17:32:28Z'
- topApiId: 'baa0dc91-9711-4b61-9c90-ce8ac0b109a9'
name: 'careweb'
pathwaysVersion: '0.1'
active: true
created: '2019-07-21T17:32:28Z'
Pagination:
type: object
properties:
pagination:
type: object
properties:
offset:
type: integer
minimum: 0
default: 0
example: 5
limit:
type: integer
example: 20
totalResultCount:
type: integer
example: 521
example:
pagination:
offset: 0
limit: 10
totalResultCount: 100
requestBodies:
TopApi:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/TopApi'