use of io.swagger.v3.oas.annotations.media.Content in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testParamContent.
@Test
public void testParamContent() {
String json = "{" + " \"openapi\": \"3.0.0\"," + " \"info\": {" + " \"title\": \"Operations\"," + " \"version\": \"0.0.0\"" + " }," + " \"paths\": {" + " \"/operations\": {" + " \"post\": {" + " \"parameters\": [" + " {" + " \"name\": \"param0\"," + " \"in\": \"query\"," + " \"content\": {" + " }" + " }," + " {" + " \"name\": \"param1\"," + " \"in\": \"query\"," + " \"content\": {" + " \"text/plain\": {" + " }" + " }" + " }," + " {" + " \"name\": \"param2\"," + " \"in\": \"query\"," + " \"content\": {" + " \"text/plain\": {" + " }," + " \"application/json\": {" + " \"schema\": {" + " \"type\": \"object\"" + " }" + " }" + " }" + " }" + " ]," + " \"responses\": {" + " \"default\": {" + " \"description\": \"None\"" + " }" + " }" + " }" + " }" + " }" + "}";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(json, null, null);
Operation post = result.getOpenAPI().getPaths().get("/operations").getPost();
Parameter param0 = post.getParameters().stream().filter(p -> "param0".equals(p.getName())).findFirst().orElseThrow(() -> new IllegalStateException("Can't find parameter=param0"));
assertEquals(result.getMessages().contains("attribute paths.'/operations'(post).parameters.[param0].content with no media type is unsupported"), true, "No media types error reported");
assertEquals(param0.getContent(), null, "Empty content");
Parameter param1 = post.getParameters().stream().filter(p -> "param1".equals(p.getName())).findFirst().orElseThrow(() -> new IllegalStateException("Can't find parameter=param1"));
assertEquals(param1.getContent().size(), 1, "Valid content size");
Parameter param2 = post.getParameters().stream().filter(p -> "param2".equals(p.getName())).findFirst().orElseThrow(() -> new IllegalStateException("Can't find parameter=param2"));
assertEquals(result.getMessages().contains("attribute paths.'/operations'(post).parameters.[param2].content with multiple media types is unsupported"), true, "Multiple media types error reported");
assertEquals(param2.getContent(), null, "Content with multiple media types");
assertEquals(result.getMessages().size(), 2, "Messages");
}
use of io.swagger.v3.oas.annotations.media.Content in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testDeserializeByteString.
@Test
public void testDeserializeByteString() {
String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + " version: 0.0.0\n" + " title: My Title\n" + "paths:\n" + " /persons:\n" + " get:\n" + " description: a test\n" + " responses:\n" + " '200':\n" + " description: Successful response\n" + " content:\n" + " '*/*':\n" + " schema:\n" + " type: object\n" + " properties:\n" + " bytes:\n" + " $ref: '#/components/schemas/ByteString'\n" + "components:\n" + " schemas:\n" + " ByteString:\n" + " type: string\n" + " format: byte\n" + " default: W.T.F?\n" + " enum:\n" + " - VGhlIHdvcmxk\n" + " - aXMgYWxs\n" + " - dGhhdCBpcw==\n" + " - dGhlIGNhc2U=\n" + " - W.T.F?\n" + "";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(yaml, null, null);
final OpenAPI resolved = new OpenAPIResolver(result.getOpenAPI(), null).resolve();
Schema byteModel = resolved.getComponents().getSchemas().get("ByteString");
assertTrue(byteModel instanceof ByteArraySchema);
List<byte[]> byteValues = byteModel.getEnum();
assertEquals(byteValues.size(), 4);
assertEquals(new String(byteValues.get(0)), "The world");
assertEquals(new String(byteValues.get(1)), "is all");
assertEquals(new String(byteValues.get(2)), "that is");
assertEquals(new String(byteValues.get(3)), "the case");
assertEquals(byteModel.getDefault(), null);
assertEquals(result.getMessages(), Arrays.asList("attribute components.schemas.ByteString.enum=`W.T.F?` is not of type `byte`", "attribute components.schemas.ByteString.default=`W.T.F?` is not of type `byte`"));
}
use of io.swagger.v3.oas.annotations.media.Content in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testIssue386.
@Test
public void testIssue386() {
String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + " description: bleh\n" + " version: 2.0.0\n" + " title: Test\n" + "paths:\n" + " /foo:\n" + " post:\n" + " responses:\n" + " '200':\n" + " description: OK\n" + " requestBody:\n" + " content:\n" + " application/json:\n" + " schema:\n" + " type: object\n" + " enum:\n" + " - id: fun\n" + " properties:\n" + " id:\n" + " type: string\n" + "components:\n" + " schemas:\n" + " Fun:\n" + " type: object\n" + " properties:\n" + " complex:\n" + " enum:\n" + " - id: 110\n" + " type: object\n" + " properties:\n" + " id:\n" + " type: string\n" + " MyEnum:\n" + " type: integer\n" + " enum:\n" + " - value: 3\n" + " description: Value 1\n" + " - value: 10\n" + " description: Value 2";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(yaml, null, null);
OpenAPI openAPI = result.getOpenAPI();
assertNotNull(openAPI);
}
use of io.swagger.v3.oas.annotations.media.Content in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testAdditionalPropertiesBoolean.
@Test
public void testAdditionalPropertiesBoolean() {
String yaml = "openapi: 3.0.0\n" + "info:\n" + " title: Test\n" + " version: 1.0.0\n" + "paths:\n" + " \"/store/inventory\":\n" + " post:\n" + " requestBody:\n" + " content:\n" + " application/json:\n" + " schema:\n" + " additionalProperties: true\n" + " responses:\n" + " '200':\n" + " description: successful operation\n" + " content:\n" + " application/json:\n" + " schema:\n" + " additionalProperties: false\n";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(yaml, null, null);
assertEquals(result.getMessages(), emptyList());
OpenAPI openAPI = result.getOpenAPI();
Schema body = openAPI.getPaths().get("/store/inventory").getPost().getRequestBody().getContent().get("application/json").getSchema();
assertEquals(body.getAdditionalProperties(), Boolean.TRUE);
assertEquals(body.getClass(), MapSchema.class);
Schema response = openAPI.getPaths().get("/store/inventory").getPost().getResponses().get("200").getContent().get("application/json").getSchema();
assertEquals(response.getAdditionalProperties(), Boolean.FALSE);
assertEquals(response.getClass(), ObjectSchema.class);
}
use of io.swagger.v3.oas.annotations.media.Content in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testEmptyDefinitions.
@Test
public void testEmptyDefinitions() throws Exception {
String yaml = "openapi: 3.0.0\n" + "servers:\n" + " - url: 'http://abc:5555/mypath'\n" + "info:\n" + " version: '1.0'\n" + " title: dd\n" + "paths:\n" + " /resource1/Id:\n" + " post:\n" + " description: ''\n" + " operationId: postOp\n" + " responses:\n" + " '200':\n" + " description: Successful\n" + " '401':\n" + " description: Access Denied\n" + " requestBody:\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/mydefinition'\n" + " required: true\n" + "components:\n" + " schemas:\n" + " mydefinition: {}";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(yaml, null, null);
OpenAPI openAPI = result.getOpenAPI();
assertNotNull(openAPI);
assertNotNull(openAPI.getComponents().getSchemas().get("mydefinition"));
}
Aggregations