use of io.swagger.v3.oas.models.Paths in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testIssue1644_NullValue.
@Test
public void testIssue1644_NullValue() throws Exception {
ParseOptions options = new ParseOptions();
String issue1644 = "openapi: 3.0.0\n" + "info:\n" + " title: Operations\n" + " version: 0.0.0\n" + "paths:\n" + " \"/operations\":\n" + " post:\n" + " parameters:\n" + " - name: param0\n" + " schema:\n" + " type: string\n" + " responses:\n" + " default:\n" + " description: None\n";
SwaggerParseResult result = new OpenAPIV3Parser().readContents(issue1644, null, options);
Assert.assertNotNull(result);
Assert.assertNotNull(result.getOpenAPI());
assertEquals(result.getMessages().size(), 1);
assertTrue(result.getMessages().contains("attribute paths.'/operations'(post).parameters.[param0].in is missing"));
assertFalse(result.getMessages().contains("attribute paths.'/operations'(post).parameters.[param0].in is not of type `string`"));
}
use of io.swagger.v3.oas.models.Paths in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testIncompatibleRefs.
@Test
public void testIncompatibleRefs() {
String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "paths:\n" + " /test:\n" + " post:\n" + " responses:\n" + " '200':\n" + " $ref: '#/components/schemas/Schema'\n" + " '400':\n" + " definitions: this is right\n" + " description: Bad Request\n" + " content:\n" + " '*/*':\n" + " schema:\n" + " $ref: '#/components/schemas/Schema'\n" + " requestBody:\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/Schema'\n" + " required: true\n" + "info:\n" + " version: ''\n" + " title: ''\n" + "components:\n" + " schemas:\n" + " Schema: {}";
SwaggerParseResult result = new OpenAPIV3Parser().readContents(yaml, null, null);
assertNotNull(result.getOpenAPI());
}
use of io.swagger.v3.oas.models.Paths in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testParseRefPathParameters.
@Test
public void testParseRefPathParameters() throws Exception {
String yaml = "openAPI: '2.0'\n" + "info:\n" + " title: test\n" + " version: '0.0.0'\n" + "parameters:\n" + " report-id:\n" + " name: id\n" + " in: path\n" + " type: string\n" + " required: true\n" + "paths:\n" + " /reports/{id}:\n" + " parameters:\n" + " - $ref: '#/parameters/report-id'\n" + " put:\n" + " parameters:\n" + " - name: id\n" + " in: body\n" + " required: true\n" + " schema:\n" + " $ref: '#/components/schemas/report'\n" + " responses:\n" + " 200:\n" + " description: ok\n" + "definitions:\n" + " report:\n" + " type: object\n" + " properties:\n" + " id:\n" + " type: string\n" + " name:\n" + " type: string\n" + " required:\n" + " - id\n" + " - name\n";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
OpenAPI openAPI = (parser.readContents(yaml, null, null)).getOpenAPI();
}
use of io.swagger.v3.oas.models.Paths in project swagger-parser by swagger-api.
the class ResolverFully method resolveFully.
public void resolveFully(OpenAPI openAPI) {
Components components = openAPI.getComponents();
if (components != null && components.getRequestBodies() != null) {
requestBodies = components.getRequestBodies();
if (requestBodies == null) {
requestBodies = new HashMap<>();
}
}
if (components != null && components.getSchemas() != null) {
schemas = components.getSchemas();
if (schemas == null) {
schemas = new HashMap<>();
}
}
if (components != null && components.getExamples() != null) {
examples = components.getExamples();
if (examples == null) {
examples = new HashMap<>();
}
}
if (components != null && components.getHeaders() != null) {
headers = components.getHeaders();
if (headers == null) {
headers = new HashMap<>();
}
}
if (components != null && components.getParameters() != null) {
parameters = components.getParameters();
if (parameters == null) {
parameters = new HashMap<>();
}
}
if (components != null && components.getLinks() != null) {
links = components.getLinks();
if (links == null) {
links = new HashMap<>();
}
}
if (components != null && components.getCallbacks() != null) {
callbacks = components.getCallbacks();
if (callbacks == null) {
callbacks = new HashMap<>();
}
}
Paths paths = openAPI.getPaths();
if (paths != null) {
for (String pathname : paths.keySet()) {
PathItem pathItem = paths.get(pathname);
resolvePath(pathItem);
}
}
}
use of io.swagger.v3.oas.models.Paths in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testConverterIssue17.
@Test
public void testConverterIssue17() throws Exception {
String yaml = "openapi: 3.0.0\n" + "info:\n" + " version: 0.0.0\n" + " title: nada\n" + "paths:\n" + " /persons:\n" + " get:\n" + " parameters:\n" + " - name: testParam\n" + " in: query\n" + " style: form\n" + " schema:\n" + " type: array\n" + " items:\n" + " type: string\n" + " responses:\n" + " '200':\n" + " description: Successful response\n" + " content:\n" + " '*/*':\n" + " schema:\n" + " $ref: '#/components/schemas/Content'\n" + "components:\n" + " schemas:\n" + " Content:\n" + " type: object";
ParseOptions options = new ParseOptions();
options.setResolve(false);
SwaggerParseResult result = new OpenAPIV3Parser().readContents(yaml, null, options);
assertNotNull(result.getOpenAPI());
assertEquals((result.getOpenAPI().getPaths().get("/persons").getGet().getResponses().get("200").getContent().get("*/*").getSchema()).get$ref(), "#/components/schemas/Content");
}
Aggregations