use of io.swagger.v3.parser.core.models.AuthorizationValue in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testShellMethod.
@Test
public void testShellMethod(@Injectable final List<AuthorizationValue> auths) {
String url = "http://localhost:${dynamicPort}/remote/spec";
url = url.replace("${dynamicPort}", String.valueOf(this.serverPort));
OpenAPI openAPI = new OpenAPIV3Parser().read(url);
Assert.assertNotNull(openAPI);
assertEquals(openAPI.getOpenapi(), "3.0.1");
}
use of io.swagger.v3.parser.core.models.AuthorizationValue in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method testSelfReferenceResolution.
@Test
public void testSelfReferenceResolution(@Injectable final List<AuthorizationValue> auths) throws Exception {
String yaml = "" + "openapi: 3.0.1\n" + "paths:\n" + " \"/selfRefB\":\n" + " get:\n" + " requestBody:\n" + " description: user to add to the system\\n\"+\n" + " content:\n" + " 'application/json':\n" + " schema:\n" + " $ref: '#/components/schemas/SchemaB'\n" + "components:\n" + " schemas:\n" + " SchemaA:\n" + " properties:\n" + " name:\n" + " type: string\n" + " modelB:\n" + " $ref: '#/components/schemas/SchemaB'\n" + " SchemaB:\n" + " properties:\n" + " modelB:\n" + " $ref: '#/components/schemas/SchemaB'";
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setResolveFully(true);
OpenAPI openAPI = new OpenAPIV3Parser().readContents(yaml, auths, options).getOpenAPI();
ResolverFully resolverUtil = new ResolverFully();
resolverUtil.resolveFully(openAPI);
RequestBody body = openAPI.getPaths().get("/selfRefB").getGet().getRequestBody();
Schema schema = body.getContent().get("application/json").getSchema();
assertEquals(schema, openAPI.getComponents().getSchemas().get("SchemaB"));
}
use of io.swagger.v3.parser.core.models.AuthorizationValue in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method selfReferenceTest.
@Test
public void selfReferenceTest(@Injectable final List<AuthorizationValue> auths) {
String yaml = "" + "openapi: 3.0.1\n" + "paths:\n" + " /selfRefA:\n" + " get:\n" + " requestBody:\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/ModelA'\n" + " responses:\n" + " default:\n" + " description: Default response\n" + " /selfRefB:\n" + " get:\n" + " requestBody:\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/ModelB'\n" + " responses:\n" + " default:\n" + " description: Default response\n" + " /selfRefC:\n" + " get:\n" + " requestBody:\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/ModelC'\n" + " responses:\n" + " default:\n" + " description: Default response\n" + " /selfRefD:\n" + " get:\n" + " responses:\n" + " default:\n" + " description: Default response\n" + " content:\n" + " '*/*':\n" + " schema:\n" + " $ref: '#/components/schemas/ModelA'\n" + " /selfRefE:\n" + " get:\n" + " responses:\n" + " default:\n" + " description: Default response\n" + " content:\n" + " '*/*':\n" + " schema:\n" + " type: array\n" + " items:\n" + " $ref: '#/components/schemas/ModelA'\n" + "info:\n" + " version: ''\n" + " title: ''\n" + "components:\n" + " schemas:\n" + " ModelA:\n" + " properties:\n" + " modelB:\n" + " $ref: '#/components/schemas/ModelB'\n" + " ModelB:\n" + " properties:\n" + " modelB:\n" + " $ref: '#/components/schemas/ModelB'\n" + " ModelC:\n" + " properties:\n" + " modelA:\n" + " $ref: '#/components/schemas/ModelA'";
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setResolveFully(true);
OpenAPI openAPI = new OpenAPIV3Parser().readContents(yaml, auths, options).getOpenAPI();
Schema schemaB = openAPI.getPaths().get("/selfRefB").getGet().getRequestBody().getContent().get("application/json").getSchema();
assertTrue(schemaB instanceof Schema);
assertEquals(openAPI.getComponents().getSchemas().get("ModelB"), schemaB);
Schema schema = openAPI.getPaths().get("/selfRefE").getGet().getResponses().get("default").getContent().get("*/*").getSchema();
assertTrue(schema instanceof ArraySchema);
ArraySchema arraySchema = (ArraySchema) schema;
assertEquals(openAPI.getComponents().getSchemas().get("ModelA"), arraySchema.getItems());
}
use of io.swagger.v3.parser.core.models.AuthorizationValue in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method resolveAllOfWithoutAggregatingParameters.
@Test
public void resolveAllOfWithoutAggregatingParameters(@Injectable final List<AuthorizationValue> auths) {
ParseOptions options = new ParseOptions();
options.setResolveFully(true);
options.setResolveCombinators(false);
// Testing components/schemas
OpenAPI openAPI = new OpenAPIV3Parser().readLocation("src/test/resources/composed.yaml", auths, options).getOpenAPI();
ComposedSchema allOf = (ComposedSchema) openAPI.getComponents().getSchemas().get("ExtendedAddress");
assertEquals(allOf.getAllOf().size(), 2);
assertTrue(allOf.getAllOf().get(0).getProperties().containsKey("street"));
assertTrue(allOf.getAllOf().get(1).getProperties().containsKey("gps"));
// Testing path item
ComposedSchema schema = (ComposedSchema) openAPI.getPaths().get("/withInvalidComposedModel").getPost().getRequestBody().getContent().get("application/json").getSchema();
// In fact the schema resolved previously is the same of /withInvalidComposedModel
assertEquals(schema, allOf);
assertEquals(schema.getAllOf().size(), 2);
assertTrue(schema.getAllOf().get(0).getProperties().containsKey("street"));
assertTrue(schema.getAllOf().get(1).getProperties().containsKey("gps"));
}
use of io.swagger.v3.parser.core.models.AuthorizationValue in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method resolveComposedReferenceAllOfSchema.
@Test
public void resolveComposedReferenceAllOfSchema(@Injectable final List<AuthorizationValue> auths) {
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setResolveFully(true);
OpenAPI openAPI = new OpenAPIV3Parser().readLocation("src/test/resources/composed.yaml", auths, options).getOpenAPI();
assertTrue(openAPI.getPaths().get("/withInvalidComposedModelArray").getPost().getRequestBody().getContent().get("application/json").getSchema() instanceof ArraySchema);
ArraySchema arraySchema = (ArraySchema) openAPI.getPaths().get("/withInvalidComposedModelArray").getPost().getRequestBody().getContent().get("application/json").getSchema();
assertTrue(arraySchema.getItems() instanceof ObjectSchema);
}
Aggregations