use of io.swagger.v3.oas.models.Paths in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testPR246.
@Test
public void testPR246() throws Exception {
String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + " description: 'Tests the allOf API for parent, interface and child models.'\n" + " version: 2.0.0\n" + " title: Test allOf API\n" + "paths:\n" + " /:\n" + " get:\n" + " responses:\n" + " '200':\n" + " description: OK\n" + " parameters: []\n" + "components:\n" + " schemas:\n" + " Pet:\n" + " type: object\n" + " required:\n" + " - id\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int64\n" + " Furry:\n" + " type: object\n" + " required:\n" + " - coatColour\n" + " properties:\n" + " coatColour:\n" + " type: string\n" + " Dog:\n" + " allOf:\n" + " - $ref: '#/components/schemas/Pet'\n" + " - $ref: '#/components/schemas/Furry'\n" + " - type: object\n" + " required:\n" + " - name\n" + " properties:\n" + " name:\n" + " type: string";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(yaml, null, null);
OpenAPI openAPI = result.getOpenAPI();
Schema dog = openAPI.getComponents().getSchemas().get("Dog");
assertNotNull(dog);
assertTrue(dog instanceof ComposedSchema);
ComposedSchema composed = (ComposedSchema) dog;
assertTrue(composed.getAllOf().get(0).get$ref() != null);
assertTrue(composed.getAllOf().size() == 3);
}
use of io.swagger.v3.oas.models.Paths in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testIssue1398.
@Test
public void testIssue1398() {
ParseOptions options = new ParseOptions();
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("issue1398.yaml", null, options);
assertEquals(result.getMessages().get(0), "attribute paths.'/pet/{petId}'(get).parameters.[petId].schemas.multipleOf value must be > 0");
}
use of io.swagger.v3.oas.models.Paths in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method testParameterOnPathLevel.
@Test
public void testParameterOnPathLevel() throws Exception {
String yaml = "openapi: 3.0.1\n" + "info:\n" + " version: '1.0.0'\n" + " title: 'title'\n" + " description: 'description'\n" + "paths:\n" + " /foo:\n" + " parameters:\n" + " - in: query\n" + " name: bar\n" + " schema:\n" + " type: string\n" + " get:\n" + " responses:\n" + " '200':\n" + " description: OK";
ParseOptions options = new ParseOptions();
options.setResolve(true);
OpenAPI openAPI = new OpenAPIV3Parser().readContents(yaml, null, options).getOpenAPI();
assertNotNull(openAPI);
List<Parameter> getParameters = openAPI.getPaths().get("/foo").getGet().getParameters();
assertNotNull(getParameters);
assertEquals(1, getParameters.size());
assertEquals("bar", getParameters.get(0).getName());
}
use of io.swagger.v3.oas.models.Paths in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method testSettingsAddParametersToEachOperationDisabled.
@Test
public void testSettingsAddParametersToEachOperationDisabled() {
String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + " title: test spec\n" + " version: '1.0'\n" + "paths:\n" + " '/test/{id}':\n" + " parameters:\n" + " - name: id\n" + " in: path\n" + " required: true\n" + " schema:\n" + " type: string\n" + " get:\n" + " description: test get\n" + " parameters:\n" + " - name: page\n" + " in: query\n" + " schema:\n" + " type: string\n" + " responses:\n" + " default:\n" + " description: test response";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(yaml, null, null);
OpenAPI swagger = result.getOpenAPI();
final OpenAPI resolved = new OpenAPIResolver(swagger, null, null, new OpenAPIResolver.Settings().addParametersToEachOperation(false)).resolve();
assertEquals(resolved.getPaths().get("/test/{id}").getParameters().size(), 1);
PathParameter pp = (PathParameter) resolved.getPaths().get("/test/{id}").getParameters().get(0);
assertEquals(pp.getName(), "id");
assertEquals(resolved.getPaths().get("/test/{id}").getGet().getParameters().size(), 1);
QueryParameter qp = (QueryParameter) resolved.getPaths().get("/test/{id}").getGet().getParameters().get(0);
assertEquals(qp.getName(), "page");
}
use of io.swagger.v3.oas.models.Paths in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testValidateExternalRefsTrue.
@Test(description = "option true, adds Original Location to messages when ref is relative/local")
public void testValidateExternalRefsTrue() {
ParseOptions options = new ParseOptions();
options.setValidateExternalRefs(true);
options.setResolve(true);
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("./swos-443/root.yaml", null, options);
OpenAPI openAPI = result.getOpenAPI();
assertNotNull(openAPI);
assertNotNull(result.getMessages());
assertEquals(result.getMessages().size(), 19);
assertTrue(result.getMessages().contains("attribute components.requestBodies.NewItem.asdasd is unexpected (./ref.yaml)"));
assertTrue(result.getMessages().contains("attribute components.requestBodies.NewItem.descasdasdription is unexpected (./ref.yaml)"));
assertTrue(result.getMessages().contains("attribute components.responses.GeneralError.descrsaiption is unexpected (./ref.yaml)"));
assertTrue(result.getMessages().contains("attribute components.responses.GeneralError.asdas is unexpected (./ref.yaml)"));
assertTrue(result.getMessages().contains("attribute components.responses.GeneralError.description is missing (./ref.yaml)"));
assertTrue(result.getMessages().contains("attribute components.schemas.Examples.nonExpected is unexpected (./ref.yaml)"));
assertTrue(result.getMessages().contains("attribute components.parameters.skipParam.[skip].in is not of type `[query|header|path|cookie]` (./ref.yaml)"));
assertTrue(result.getMessages().contains("attribute components.securitySchemes.api_key.namex is unexpected (./ref.yaml)"));
assertTrue(result.getMessages().contains("attribute components.securitySchemes.api_key.name is missing (./ref.yaml)"));
assertTrue(result.getMessages().contains("attribute components.callbacks.webhookVerificationEvent.postx is unexpected (./ref.yaml)"));
assertTrue(result.getMessages().contains("attribute components.headers.X-Rate-Limit-Limit.descriptasdd is unexpected (./ref.yaml)"));
assertTrue(result.getMessages().contains("attribute components.links.unsubscribe.parametersx is unexpected (./ref.yaml)"));
assertTrue(result.getMessages().contains("attribute components.examples.response-example.summaryx is unexpected (./ref.yaml)"));
assertTrue(result.getMessages().contains("attribute components.examples.response-example. value and externalValue are both present (./ref.yaml)"));
assertTrue(result.getMessages().contains("attribute components.callbacks.failed.wrongField is not of type `object` (./ref.yaml)"));
assertTrue(result.getMessages().contains("attribute paths.~1refPet(get).responses is missing (./ref.yaml)"));
// error message in main file
assertTrue(result.getMessages().contains("attribute components.schemas.InvalidSchema.invalid is unexpected"));
assertTrue(result.getMessages().contains("attribute components.schemas.ErrorModel.properties is not of type `object` (./ref.yaml)"));
assertTrue(result.getMessages().contains("attribute components.schemas.Examples.properties is not of type `object` (./ref.yaml)"));
}
Aggregations