io.swagger.v3.parser.core.models.ParseOptions Java Examples
The following examples show how to use
io.swagger.v3.parser.core.models.ParseOptions.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OpenAPIResolverTest.java From swagger-parser with Apache License 2.0 | 6 votes |
@Test public void testComposedSchemaAdjacent(@Injectable final List<AuthorizationValue> auths) throws Exception { ParseOptions options = new ParseOptions(); options.setResolve(true); options.setResolveFully(true); OpenAPI openAPI = new OpenAPIV3Parser().read("src/test/resources/composedSchemaRef.yaml", auths, options); Assert.assertNotNull(openAPI); Assert.assertTrue(openAPI.getComponents().getSchemas().size() == 5); Schema schema = openAPI.getPaths().get("/path").getGet().getResponses().get("200").getContent().get("application/json").getSchema(); Assert.assertTrue(schema.getProperties().size() == 4); ComposedSchema schemaOneOf = (ComposedSchema) openAPI.getPaths().get("/oneOf").getGet().getResponses().get("200").getContent().get("application/json").getSchema(); Assert.assertTrue(schemaOneOf.getOneOf().size() == 3); ComposedSchema schemaAnyOf = (ComposedSchema) openAPI.getPaths().get("/anyOf").getGet().getResponses().get("200").getContent().get("application/json").getSchema(); Assert.assertTrue(schemaAnyOf.getAnyOf().size() == 3); }
Example #2
Source File: OAIDeserializationTest.java From swagger-parser with Apache License 2.0 | 6 votes |
@Test public void testDeserializeSimpleDefinition() throws Exception { String json = "{\n" + " \"openapi\": \"3.0.1\",\n" + " \"info\": {\n" + " \"title\": \"Swagger Petstore\",\n" + " \"description\": \"This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.\",\n" + " \"termsOfService\": \"http://swagger.io/terms/\",\n" + " \"contact\": {\n" + " \"email\": \"[email protected]\"\n" + " },\n" + " \"license\": {\n" + " \"name\": \"Apache 2.0\",\n" + " \"url\": \"http://www.apache.org/licenses/LICENSE-2.0.html\"\n" + " },\n" + " \"version\": \"1.0.0\"\n" + " }\n" + "}"; ParseOptions options = new ParseOptions(); options.setResolve(true); SwaggerParseResult result = new OpenAPIV3Parser().readContents(json, null, options); assertNotNull(result.getOpenAPI()); }
Example #3
Source File: SpringCodegenTest.java From openapi-generator with Apache License 2.0 | 6 votes |
private Map<String, File> generateFiles(SpringCodegen codegen, String filePath) throws IOException { final File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); output.deleteOnExit(); final String outputPath = output.getAbsolutePath().replace('\\', '/'); codegen.setOutputDir(output.getAbsolutePath()); codegen.additionalProperties().put(CXFServerFeatures.LOAD_TEST_DATA_FROM_FILE, "true"); final ClientOptInput input = new ClientOptInput(); final OpenAPI openAPI = new OpenAPIParser().readLocation(filePath, null, new ParseOptions()).getOpenAPI(); input.openAPI(openAPI); input.config(codegen); final DefaultGenerator generator = new DefaultGenerator(); List<File> files = generator.opts(input).generate(); return files.stream().collect(Collectors.toMap(e -> e.getName().replace(outputPath, ""), i -> i)); }
Example #4
Source File: FileReferenceTest.java From swagger-parser with Apache License 2.0 | 6 votes |
@Test public void testRelativeRefIssue421() { ParseOptions options = new ParseOptions(); options.setResolve(true); SwaggerParseResult result = new OpenAPIV3Parser().readLocation("./src/test/resources/main.yaml", null, options); assertNotNull(result.getOpenAPI()); OpenAPI swagger = result.getOpenAPI(); assertNotNull(swagger); assertNotNull(swagger.getPaths().get("pets")); assertNotNull(swagger.getPaths().get("pets").getGet()); assertNotNull(swagger.getPaths().get("pets").getGet().getResponses()); assertNotNull(swagger.getPaths().get("pets").getGet().getResponses().get("200")); assertNotNull(swagger.getPaths().get("pets").getGet().getResponses().get("200").getContent().get("*/*").getSchema()); assertTrue(swagger.getPaths().get("pets").getGet().getResponses().get("200").getContent().get("*/*").getSchema().get$ref() != null); assertEquals(swagger.getPaths().get("pets").getGet().getResponses().get("200").getContent().get("*/*").getSchema().get$ref(), "#/components/schemas/Pet"); assertTrue(swagger.getComponents().getSchemas().get("Pet") instanceof Schema); assertTrue(swagger.getComponents().getSchemas().get("Pet").getProperties().size() == 2); }
Example #5
Source File: OpenAPIV3ParserTest.java From swagger-parser with Apache License 2.0 | 6 votes |
@Test public void shouldParseApiWithMultipleParameterReferences() { // given String location = "src/test/resources/issue-1063/api.yaml"; ParseOptions options = new ParseOptions(); OpenAPIV3Parser tested = new OpenAPIV3Parser(); // when SwaggerParseResult result = tested.readLocation(location, emptyList(), options); // then OpenAPI api = result.getOpenAPI(); Map<String, Parameter> parameters = api.getComponents().getParameters(); assertThat(parameters.keySet(), equalTo(new HashSet<>(asList("IdParam", "NameParam")))); assertThat(parameters.get("IdParam").getName(), equalTo("id")); assertThat(parameters.get("NameParam").getName(), equalTo("name")); assertThat(result.getMessages(), equalTo(emptyList())); }
Example #6
Source File: OpenAPIV3ParserTest.java From swagger-parser with Apache License 2.0 | 6 votes |
@Test public void testIssue1063() { // given String location = "src/test/resources/issue-1063/openapi.yaml"; ParseOptions options = new ParseOptions(); options.setResolve(true); OpenAPIV3Parser tested = new OpenAPIV3Parser(); // when SwaggerParseResult result = tested.readLocation(location, emptyList(), options); // then OpenAPI api = result.getOpenAPI(); assertEquals(api.getPaths().get("/anPath").getGet().getParameters().get(0).getName(), "customer-id"); assertEquals(api.getPaths().get("/anPath").getGet().getParameters().get(1).getName(), "unit-id"); assertThat(result.getMessages(), equalTo(emptyList())); }
Example #7
Source File: JavaJAXRSSpecServerCodegenTest.java From openapi-generator with Apache License 2.0 | 6 votes |
@Test public void addsImportForSetResponse() throws IOException { File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); output.deleteOnExit(); String outputPath = output.getAbsolutePath().replace('\\', '/'); OpenAPI openAPI = new OpenAPIParser() .readLocation("src/test/resources/3_0/setResponse.yaml", null, new ParseOptions()).getOpenAPI(); codegen.setOutputDir(output.getAbsolutePath()); codegen.additionalProperties().put(CXFServerFeatures.LOAD_TEST_DATA_FROM_FILE, "true"); ClientOptInput input = new ClientOptInput() .openAPI(openAPI) .config(codegen); DefaultGenerator generator = new DefaultGenerator(); generator.opts(input).generate(); Path path = Paths.get(outputPath + "/src/gen/java/org/openapitools/api/ExamplesApi.java"); assertFileContains(path, "\nimport java.util.Set;\n"); }
Example #8
Source File: OpenAPIV3ParserTest.java From swagger-parser with Apache License 2.0 | 6 votes |
@Test public void testInlineModelResolverByUrl(){ String url = "http://localhost:${dynamicPort}/remote/json"; url = url.replace("${dynamicPort}", String.valueOf(this.serverPort)); ParseOptions options = new ParseOptions(); options.setFlatten(true); SwaggerParseResult result = new OpenAPIV3Parser().readLocation(url,new ArrayList<>(),options); Assert.assertNotNull(result); OpenAPI openAPI = result.getOpenAPI(); Assert.assertNotNull(openAPI); Schema user = openAPI.getComponents().getSchemas().get("User"); assertNotNull(user); Schema address = (Schema)user.getProperties().get("address"); assertTrue((address.get$ref()!= null)); Schema userAddress = openAPI.getComponents().getSchemas().get("User_address"); assertNotNull(userAddress); assertNotNull(userAddress.getProperties().get("city")); assertNotNull(userAddress.getProperties().get("street")); }
Example #9
Source File: ExtensionsUtilTest.java From swagger-inflector with Apache License 2.0 | 6 votes |
@Test public void testArrayParam(@Injectable final List<AuthorizationValue> auths) throws IOException{ ParseOptions options = new ParseOptions(); options.setResolve(true); options.setResolveFully(true); String pathFile = FileUtils.readFileToString(new File("./src/test/swagger/oas3.yaml"),"UTF-8"); SwaggerParseResult result = new OpenAPIV3Parser().readContents(pathFile, auths, options); OpenAPI openAPI = result.getOpenAPI(); new ExtensionsUtil().addExtensions(openAPI); Operation operation = openAPI.getPaths().get("/pet").getPost(); RequestBody body = operation.getRequestBody(); assertNotNull(body); Schema model = body.getContent().get("application/json").getSchema(); assertEquals("object", model.getType()); }
Example #10
Source File: JavaJaxrsBaseTest.java From openapi-generator with Apache License 2.0 | 6 votes |
@Test public void doNotAddDefaultValueDocumentationForContainers() throws IOException { File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); output.deleteOnExit(); String outputPath = output.getAbsolutePath().replace('\\', '/'); OpenAPI openAPI = new OpenAPIParser() .readLocation("src/test/resources/3_0/arrayParameter.yaml", null, new ParseOptions()).getOpenAPI(); codegen.setOutputDir(output.getAbsolutePath()); codegen.additionalProperties().put(CXFServerFeatures.LOAD_TEST_DATA_FROM_FILE, "true"); ClientOptInput input = new ClientOptInput() .openAPI(openAPI) .config(codegen); DefaultGenerator generator = new DefaultGenerator(); generator.opts(input).generate(); assertFileNotContains(Paths.get(outputPath + "/src/gen/java/org/openapitools/api/ExamplesApi.java"), "DefaultValue"); }
Example #11
Source File: HaskellServantCodegenTest.java From openapi-generator with Apache License 2.0 | 6 votes |
@Test public void testGenerateRootEndpoint() throws IOException { // given File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); output.deleteOnExit(); String outputPath = output.getAbsolutePath().replace('\\', '/'); final HaskellServantCodegen codegen = new HaskellServantCodegen(); codegen.setOutputDir(output.getAbsolutePath()); OpenAPI openAPI = new OpenAPIParser() .readLocation("src/test/resources/3_0/rootOperation.yaml", null, new ParseOptions()) .getOpenAPI(); ClientOptInput input = new ClientOptInput(); input.setOpenAPI(openAPI); input.setConfig(codegen); // when DefaultGenerator generator = new DefaultGenerator(); generator.setGenerateMetadata(false); generator.opts(input).generate(); // then TestUtils.assertFileNotContains(Paths.get(outputPath + "/lib/RootOperation/API.hs"), "\"\" :>"); }
Example #12
Source File: OpenAPIResolverTest.java From swagger-parser with Apache License 2.0 | 6 votes |
@Test public void recursiveIssue984() { ParseOptions parseOptions = new ParseOptions(); parseOptions.setResolve(true); parseOptions.setResolveFully(true); OpenAPI openAPI = new OpenAPIV3Parser().read("issue-984-simple.yaml", null, parseOptions); if (openAPI == null) fail("failed parsing issue-984"); try { Json.pretty(openAPI); //System.out.println(Json.pretty(openAPI)); } catch (Exception e) { e.printStackTrace(); fail("Recursive loop found"); } }
Example #13
Source File: OpenAPIV3ParserTest.java From swagger-parser with Apache License 2.0 | 6 votes |
@Test public void testIssue834() { ParseOptions options = new ParseOptions(); options.setResolve(true); SwaggerParseResult result = new OpenAPIV3Parser().readLocation("issue-834/index.yaml", null, options); assertNotNull(result.getOpenAPI()); Content foo200Content = result.getOpenAPI().getPaths().get("/foo").getGet().getResponses().get("200").getContent(); assertNotNull(foo200Content); String foo200SchemaRef = foo200Content.get("application/json").getSchema().get$ref(); assertEquals(foo200SchemaRef, "#/components/schemas/schema"); Content foo300Content = result.getOpenAPI().getPaths().get("/foo").getGet().getResponses().get("300").getContent(); assertNotNull(foo300Content); String foo300SchemaRef = foo300Content.get("application/json").getSchema().get$ref(); assertEquals(foo300SchemaRef, "#/components/schemas/schema"); Content bar200Content = result.getOpenAPI().getPaths().get("/bar").getGet().getResponses().get("200").getContent(); assertNotNull(bar200Content); String bar200SchemaRef = bar200Content.get("application/json").getSchema().get$ref(); assertEquals(bar200SchemaRef, "#/components/schemas/schema"); }
Example #14
Source File: OpenAPIV3ParserTest.java From swagger-parser with Apache License 2.0 | 6 votes |
@Test public void testCodegenIssue8601() { OpenAPIV3Parser openApiParser = new OpenAPIV3Parser(); ParseOptions options = new ParseOptions(); options.setResolve(true); options.setFlatten(true); SwaggerParseResult parseResult = openApiParser.readLocation("codegen-issue-8601.yaml", null, options); OpenAPI openAPI = parseResult.getOpenAPI(); assertNotNull(openAPI.getComponents().getSchemas().get("status")); assertNotNull(openAPI.getComponents().getSchemas().get("body")); assertNotNull(openAPI.getComponents().getSchemas().get("inline_response_200")); assertNotNull(openAPI.getComponents().getSchemas().get("body_1")); assertNotNull(openAPI.getComponents().getSchemas().get("Test1")); assertNotNull(openAPI.getComponents().getSchemas().get("Test2")); }
Example #15
Source File: OpenAPIParserTest.java From swagger-parser with Apache License 2.0 | 6 votes |
@Test public void testIssueRelativeRefs1(){ String location = "specs2/my-domain/test-api/v1/test-api-swagger_v1.json"; ParseOptions po = new ParseOptions(); po.setResolve(true); SwaggerParseResult result = new OpenAPIParser().readLocation(location, null, po); assertNotNull(result.getOpenAPI()); OpenAPI openAPI = result.getOpenAPI(); Map<String, Schema> schemas = openAPI.getComponents().getSchemas(); Assert.assertTrue(schemas.get("test-api-schema_v01").getProperties().get("testingApi") instanceof ArraySchema); ArraySchema arraySchema = (ArraySchema) schemas.get("test-api-schema_v01").getProperties().get("testingApi"); Schema prop = (Schema) arraySchema.getItems().getProperties().get("itemID"); assertEquals(prop.get$ref(),"#/components/schemas/simpleIDType_v01"); }
Example #16
Source File: OpenAPIV3ParserTest.java From swagger-parser with Apache License 2.0 | 6 votes |
@Test public void testIssueFlattenAdditionalPropertiesSchemaInlineModelTrue() { OpenAPIV3Parser openApiParser = new OpenAPIV3Parser(); ParseOptions options = new ParseOptions(); options.setResolve(true); options.setFlatten(true); options.setFlattenComposedSchemas(true); options.setCamelCaseFlattenNaming(true); SwaggerParseResult parseResult = openApiParser.readLocation("additionalPropertiesFlatten.yaml", null, options); OpenAPI openAPI = parseResult.getOpenAPI(); //responses assertNotNull(openAPI.getComponents().getSchemas().get("Inline_response_map200")); assertEquals(((ComposedSchema)openAPI.getComponents().getSchemas().get("Inline_response_map200")).getOneOf().get(0).get$ref(),"#/components/schemas/Macaw1"); assertNotNull(openAPI.getComponents().getSchemas().get("Inline_response_map_items404")); assertEquals(((ComposedSchema)openAPI.getComponents().getSchemas().get("Inline_response_map_items404")).getAnyOf().get(0).get$ref(),"#/components/schemas/Macaw2"); }
Example #17
Source File: OpenAPIV3Parser.java From swagger-parser with Apache License 2.0 | 6 votes |
private SwaggerParseResult resolve(SwaggerParseResult result, List<AuthorizationValue> auth, ParseOptions options, String location) { try { if (options != null) { if (options.isResolve() || options.isResolveFully()) { result.setOpenAPI(new OpenAPIResolver(result.getOpenAPI(), emptyListIfNull(auth), location).resolve()); if (options.isResolveFully()) { new ResolverFully(options.isResolveCombinators()).resolveFully(result.getOpenAPI()); } } if (options.isFlatten()) { final InlineModelResolver inlineModelResolver = new InlineModelResolver(options.isFlattenComposedSchemas(), options.isCamelCaseFlattenNaming(), options.isSkipMatches()); inlineModelResolver.flatten(result.getOpenAPI()); } } } catch (Exception e) { LOGGER.warn("Exception while resolving:", e); result.setMessages(Collections.singletonList(e.getMessage())); } return result; }
Example #18
Source File: OpenAPIResolverTest.java From swagger-parser with Apache License 2.0 | 5 votes |
@Test public void testRefNameConflicts() throws Exception { ParseOptions options = new ParseOptions(); options.setResolveFully(true); OpenAPI openAPI = new OpenAPIV3Parser().readLocation("/refs-name-conflict/a.yaml",null, options).getOpenAPI(); assertEquals("local", ((Schema) openAPI.getPaths().get("/newPerson").getPost().getResponses().get("200").getContent().get("*/*").getSchema().getProperties().get("location")).getExample()); assertEquals("referred", ((Schema)openAPI.getPaths().get("/oldPerson").getPost().getResponses().get("200").getContent().get("*/*").getSchema().getProperties().get("location")).getExample()); assertEquals("referred", ((Schema)openAPI.getPaths().get("/yetAnotherPerson").getPost().getResponses().get("200").getContent().get("*/*").getSchema().getProperties().get("location")).getExample()); assertEquals("local", ((Schema) openAPI.getComponents().getSchemas().get("PersonObj").getProperties().get("location")).getExample()); assertEquals("referred", ((Schema) openAPI.getComponents().getSchemas().get("PersonObj_2").getProperties().get("location")).getExample()); }
Example #19
Source File: OpenAPIV3ParserTest.java From swagger-parser with Apache License 2.0 | 5 votes |
@Test(description = "Issue 855: Request Body internal refs are not being resolved") public void shouldParseRequestBody() { ParseOptions parseOptions = new ParseOptions(); parseOptions.setResolveFully(true); OpenAPI openAPI = new OpenAPIV3Parser().read("src/test/resources/issue_855.yaml", null, parseOptions); Content actualComponentContent = openAPI.getComponents().getRequestBodies().get("ASinglePet").getContent(); Content actualPathContent = openAPI.getPaths().get("/adopt").getPost().getRequestBody().getContent(); Map properties = actualComponentContent.get("application/petstore+json").getSchema().getProperties(); assertNotNull(properties); assertEquals(properties.size(), 2); assertNotNull(actualPathContent); assertEquals(actualPathContent, actualComponentContent); }
Example #20
Source File: OpenAPIV3ParserTest.java From swagger-parser with Apache License 2.0 | 5 votes |
@Test public void testIssue1039() { ParseOptions options = new ParseOptions(); options.setResolve(true); SwaggerParseResult parseResult = new OpenAPIV3Parser().readLocation("issue_1039.yaml", null, options); OpenAPI apispec = parseResult.getOpenAPI(); assertNotNull(apispec); assertEquals(apispec.getPaths().get("/pets").getGet().getParameters().get(0).getSchema().getType(),"array"); }
Example #21
Source File: OpenAPIResolverTest.java From swagger-parser with Apache License 2.0 | 5 votes |
@Test public void referringSpecWithoutComponentsTag() throws Exception { ParseOptions resolve = new ParseOptions(); resolve.setResolveFully(true); final OpenAPI openAPI = new OpenAPIV3Parser().read("./ref-without-component/a.yaml", null, resolve); Map<String, Schema> schemas = openAPI.getComponents().getSchemas(); Assert.assertEquals("Example value", schemas.get("CustomerType").getExample()); }
Example #22
Source File: FileReferenceTest.java From swagger-parser with Apache License 2.0 | 5 votes |
@Test public void testIssue310() { ParseOptions options = new ParseOptions(); options.setResolve(true); SwaggerParseResult result = new OpenAPIV3Parser().readLocation("./src/test/resources/nested-file-references/issue-310.yaml", null, options); assertNotNull(result.getOpenAPI()); OpenAPI swagger = result.getOpenAPI(); assertTrue(swagger.getComponents().getSchemas().size() == 2); assertTrue(swagger.getComponents().getSchemas().get("Paging").getProperties().size() == 1); }
Example #23
Source File: OpenAPIResolverTest.java From swagger-parser with Apache License 2.0 | 5 votes |
@Test public void recursiveResolving2() { ParseOptions parseOptions = new ParseOptions(); parseOptions.setResolve(true); parseOptions.setResolveFully(true); OpenAPI openAPI = new OpenAPIV3Parser().read("recursive2.yaml", null, parseOptions); try { Json.mapper().writeValueAsString(openAPI); } catch (Exception e) { fail("Recursive loop found"); } }
Example #24
Source File: OpenAPIParserTest.java From swagger-parser with Apache License 2.0 | 5 votes |
@Test public void testIssue887() { ParseOptions options = new ParseOptions(); SwaggerParseResult result = new OpenAPIParser().readLocation("apiWithMultipleTags.json", null, null); System.out.println(result.getMessages()); assertNotNull(result); assertNotNull(result.getOpenAPI()); assertEquals(result.getMessages().get(1), "attribute tags.sample is repeated"); }
Example #25
Source File: ExampleBuilderTest.java From swagger-inflector with Apache License 2.0 | 5 votes |
@Test public void testRefAndInlineAllOf(@Injectable final List<AuthorizationValue> auths) throws Exception { ParseOptions options = new ParseOptions(); options.setResolve(true); options.setResolveFully(true); OpenAPI openAPI = new OpenAPIV3Parser().read("src/test/swagger/allOfAndRef.yaml",auths,options); Assert.assertNotNull(openAPI); Assert.assertTrue(openAPI.getComponents().getSchemas().size() == 2); Assert.assertNotNull(openAPI.getComponents().getSchemas().get("UserEx")); Assert.assertNotNull(openAPI.getComponents().getSchemas().get("User")); Assert.assertTrue(openAPI.getPaths().get("/refToAllOf").getGet().getResponses().get("200").getContent().get("application/json").getSchema().getProperties().size() == 2); }
Example #26
Source File: OpenAPIV3ParserTest.java From swagger-parser with Apache License 2.0 | 5 votes |
@Test public void testResolveEmpty(@Injectable final List<AuthorizationValue> auths) throws Exception{ String pathFile = FileUtils.readFileToString(new File("src/test/resources/empty-oas.yaml")); ParseOptions options = new ParseOptions(); options.setResolveFully(true); SwaggerParseResult result = new OpenAPIV3Parser().readContents(pathFile, auths, options ); Assert.assertNotNull(result); Assert.assertNotNull(result.getOpenAPI()); }
Example #27
Source File: OpenAPIV3ParserTest.java From swagger-parser with Apache License 2.0 | 5 votes |
@Test public void testIssue1147() { ParseOptions options = new ParseOptions(); options.setResolve(true); options.setFlatten(true); SwaggerParseResult parseResult = new OpenAPIV3Parser().readLocation("issue-1147/issue1147.yaml", null, options); OpenAPI apispec = parseResult.getOpenAPI(); assertNotNull(apispec); assertEquals(((Schema)apispec.getComponents().getSchemas().get("StringObject").getProperties().get("val")).get$ref(),"#/components/schemas/String"); }
Example #28
Source File: OpenAPIDeserializerTest.java From swagger-parser with Apache License 2.0 | 5 votes |
@Test public void testOptionalParameter(@Injectable List<AuthorizationValue> auths) { String yaml = "openapi: 3.0.1\n" + "paths:\n" + " \"/pet\":\n" + " summary: summary\n" + " description: description\n" + " post:\n" + " summary: Add a new pet to the store\n" + " description: ''\n" + " operationId: addPet\n" + " parameters:\n" + " - name: status\n" + " in: query\n" + " description: Status values that need to be considered for filter\n" + " schema:\n" + " type: array\n" + " items:\n" + " type: string\n" + " enum:\n" + " - available\n" + " - pending\n" + " - sold\n" + " default: available"; OpenAPIV3Parser parser = new OpenAPIV3Parser(); ParseOptions options = new ParseOptions(); options.setResolve(true); SwaggerParseResult result = parser.readContents(yaml,auths,options); OpenAPI openAPI = result.getOpenAPI(); Parameter parameter = openAPI.getPaths().get("/pet").getPost().getParameters().get(0); Assert.assertFalse(parameter.getRequired()); }
Example #29
Source File: FileReferenceTest.java From swagger-parser with Apache License 2.0 | 5 votes |
@Test public void testIssue421() { ParseOptions options = new ParseOptions(); options.setResolve(true); SwaggerParseResult result = new OpenAPIV3Parser().readLocation("./src/test/resources/nested-file-references/issue-421.yaml", null, options); assertNotNull(result.getOpenAPI()); OpenAPI swagger = result.getOpenAPI(); assertNotNull(swagger.getPaths().get("/pet/{petId}")); assertNotNull(swagger.getPaths().get("/pet/{petId}").getGet()); assertNotNull(swagger.getPaths().get("/pet/{petId}").getGet().getParameters()); assertTrue(swagger.getPaths().get("/pet/{petId}").getGet().getParameters().size() == 1); assertTrue(swagger.getPaths().get("/pet/{petId}").getGet().getParameters().get(0).getName().equals("petId")); assertTrue(swagger.getComponents().getSchemas().get("Pet") instanceof Schema); assertTrue(swagger.getComponents().getSchemas().get("Pet").getProperties().size() == 6); assertNotNull(swagger.getPaths().get("/pet/{petId}").getPost()); assertNotNull(swagger.getPaths().get("/pet/{petId}").getPost().getParameters()); assertTrue(swagger.getPaths().get("/pet/{petId}").getPost().getParameters().size() == 1); assertTrue(swagger.getPaths().get("/pet/{petId}").getPost().getRequestBody() != null); assertTrue(swagger.getPaths().get("/pet/{petId}").getPost().getRequestBody().get$ref() != null); assertEquals(swagger.getPaths().get("/pet/{petId}").getPost().getRequestBody().get$ref(),"#/components/requestBodies/requestBody"); assertTrue(swagger.getPaths().get("/pet/{petId}").getPost().getRequestBody().get$ref().equals("#/components/requestBodies/requestBody")); assertNotNull(swagger.getPaths().get("/store/order")); assertNotNull(swagger.getPaths().get("/store/order").getPost()); assertNotNull(swagger.getPaths().get("/store/order").getPost().getRequestBody()); assertNotNull(swagger.getPaths().get("/store/order").getPost().getRequestBody().getContent().get("application/json").getSchema()); assertTrue(swagger.getPaths().get("/store/order").getPost().getRequestBody().getContent().get("application/json").getSchema().get$ref() != null); assertTrue(swagger.getPaths().get("/store/order").getPost().getRequestBody().getContent().get("application/json").getSchema().get$ref().equals("#/components/schemas/Order")); assertTrue(swagger.getComponents().getSchemas().get("Order") instanceof Schema); assertTrue(swagger.getComponents().getSchemas().get("Order").getProperties().size() == 6); }
Example #30
Source File: FileReferenceTest.java From swagger-parser with Apache License 2.0 | 5 votes |
@Test public void testIssue822() { ParseOptions options = new ParseOptions(); options.setResolve(true); SwaggerParseResult result = new OpenAPIV3Parser().readLocation("./src/test/resources/issue-822.yaml", null, options); OpenAPI swagger = result.getOpenAPI(); assertNotNull(swagger.getPaths().get("/foo").getGet()); assertNotNull(swagger.getPaths().get("/bar/wtf").getGet()); assertNull(swagger.getPaths().get("/bar/haha").getGet()); assertNotNull(swagger.getPaths().get("/wtf/{bar}").getGet()); assertNotNull(swagger.getPaths().get("/haha/{bar}").getGet()); assertNull(swagger.getPaths().get("/haha2/{bar}").getGet()); }