use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.
the class OpenAPIParserTest method test30.
@Test
public void test30() {
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\": \"apiteam@swagger.io\"\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 OpenAPIParser().readContents(json, null, options);
assertNotNull(result);
assertNotNull(result.getOpenAPI());
assertEquals(result.getOpenAPI().getOpenapi(), "3.0.1");
}
use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.
the class OpenAPIParserTest method testIssue1086.
public void testIssue1086() {
OpenAPIParser openApiParser = new OpenAPIParser();
ParseOptions options = new ParseOptions();
OpenAPI openAPI = openApiParser.readLocation("issue1086.yaml", null, options).getOpenAPI();
Map<String, Schema> schemas = openAPI.getComponents().getSchemas();
ObjectSchema schema = (ObjectSchema) schemas.get("AssessCandidate").getProperties().get("test_results");
Schema score = schema.getProperties().get("score");
assertEquals(score.getMultipleOf().intValue(), 1);
}
use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.
the class OpenAPIParserTest method testIssueRelativeRefs1.
@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");
}
use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.
the class OpenAPIParserTest method testIssue1621.
@Test
public void testIssue1621() {
final ParseOptions parseOptions = new ParseOptions();
parseOptions.setResolve(true);
parseOptions.setResolveFully(true);
parseOptions.setResolveCombinators(false);
OpenAPIParser openAPIParser = new OpenAPIParser();
SwaggerParseResult swaggerParseResult = openAPIParser.readLocation("issue-1621/example.openapi.yaml", null, parseOptions);
assertEquals(0, swaggerParseResult.getMessages().size());
OpenAPI api = swaggerParseResult.getOpenAPI();
assertEquals("POST Example", api.getPaths().get("/example").getPost().getRequestBody().getContent().get("application/json").getSchema().getTitle());
}
use of io.swagger.v3.parser.core.models.ParseOptions in project swagger-parser by swagger-api.
the class OpenAPIParserTest method testIssue813.
@Test
public void testIssue813() throws Exception {
String inputSpec = "{\n" + " \"swagger\": \"2.0\",\n" + " \"info\": {\n" + " \"description\": \"This is a sample server Petstore server. You can find out more about Swagger at <a href=\\\"http://swagger.io\\\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \\\"special-key\\\" to test the authorization filters\",\n" + " \"version\": \"1.0.0\",\n" + " \"title\": \"Swagger Petstore\",\n" + " \"termsOfService\": \"http://helloreverb.com/terms/\",\n" + " \"contact\": {\n" + " \"email\": \"apiteam@wordnik.com\"\n" + " },\n" + " \"license\": {\n" + " \"name\": \"Apache-2.0\",\n" + " \"url\": \"http://www.apache.org/licenses/LICENSE-2.0.html\"\n" + " }\n" + " },\n" + " \"host\": \"petstore.swagger.io\",\n" + " \"basePath\": \"/v2\",\n" + " \"schemes\": [\n" + " \"http\"\n" + " ],\n" + " \"paths\": {\n" + " \"/pet\": {\n" + " \"post\": {\n" + " \"tags\": [\n" + " \"pet\"\n" + " ],\n" + " \"summary\": \"Add a new pet to the store\",\n" + " \"description\": \"\",\n" + " \"operationId\": \"addPet\",\n" + " \"consumes\": [\n" + " \"application/json\",\n" + " \"application/xml\"\n" + " ],\n" + " \"produces\": [\n" + " \"application/json\",\n" + " \"application/xml\"\n" + " ],\n" + " \"parameters\": [{\n" + " \"in\": \"body\",\n" + " \"name\": \"body\",\n" + " \"description\": \"Pet object that needs to be added to the store\",\n" + " \"required\": false,\n" + " \"schema\": {\n" + " \"$ref\": \"#/definitions/Pet\"\n" + " }\n" + " }],\n" + " \"responses\": {\n" + " \"405\": {\n" + " \"description\": \"Invalid input\"\n" + " }\n" + " },\n" + " \"security\": [{\n" + " \"petstore_auth\": [\n" + " \"write:pets\",\n" + " \"read:pets\"\n" + " ]\n" + " }]\n" + " },\n" + " \"put\": {\n" + " \"tags\": [\n" + " \"pet\"\n" + " ],\n" + " \"summary\": \"Update an existing pet\",\n" + " \"description\": \"\",\n" + " \"operationId\": \"updatePet\",\n" + " \"consumes\": [\n" + " \"application/json\",\n" + " \"application/xml\"\n" + " ],\n" + " \"produces\": [\n" + " \"application/json\",\n" + " \"application/xml\"\n" + " ],\n" + " \"parameters\": [{\n" + " \"in\": \"body\",\n" + " \"name\": \"body\",\n" + " \"description\": \"Pet object that needs to be added to the store\",\n" + " \"required\": false,\n" + " \"schema\": {\n" + " \"$ref\": \"#/definitions/Pet\"\n" + " }\n" + " }],\n" + " \"responses\": {\n" + " \"405\": {\n" + " \"description\": \"Validation exception\"\n" + " },\n" + " \"404\": {\n" + " \"description\": \"Pet not found\"\n" + " },\n" + " \"400\": {\n" + " \"description\": \"Invalid ID supplied\"\n" + " }\n" + " },\n" + " \"security\": [{\n" + " \"petstore_auth\": [\n" + " \"write:pets\",\n" + " \"read:pets\"\n" + " ]\n" + " }]\n" + " }\n" + " },\n" + " \"securityDefinitions\": {\n" + " \"api_key\": {\n" + " \"type\": \"apiKey\",\n" + " \"name\": \"api_key\",\n" + " \"in\": \"header\"\n" + " },\n" + " \"petstore_auth\": {\n" + " \"type\": \"oauth2\",\n" + " \"authorizationUrl\": \"http://petstore.swagger.io/api/oauth/dialog\",\n" + " \"flow\": \"implicit\",\n" + " \"scopes\": {\n" + " \"write:pets\": \"modify pets in your account\",\n" + " \"read:pets\": \"read your pets\"\n" + " }\n" + " }\n" + " },\n" + " \"definitions\": {\n" + " \"Pet\": {\n" + " \"required\": [\n" + " \"name\",\n" + " \"photoUrls\"\n" + " ],\n" + " \"properties\": {\n" + " \"id\": {\n" + " \"type\": \"integer\",\n" + " \"format\": \"int64\"\n" + " },\n" + " \"category\": {\n" + " \"$ref\": \"#/definitions/Category\"\n" + " },\n" + " \"name\": {\n" + " \"type\": \"string\",\n" + " \"example\": \"doggie\"\n" + " },\n" + " \"photoUrls\": {\n" + " \"type\": \"array\",\n" + " \"xml\": {\n" + " \"name\": \"photoUrl\",\n" + " \"wrapped\": true\n" + " },\n" + " \"items\": {\n" + " \"type\": \"string\"\n" + " }\n" + " },\n" + " \"tags\": {\n" + " \"type\": \"array\",\n" + " \"xml\": {\n" + " \"name\": \"tag\",\n" + " \"wrapped\": true\n" + " },\n" + " \"items\": {\n" + " \"$ref\": \"#/definitions/Tag\"\n" + " }\n" + " },\n" + " \"status\": {\n" + " \"type\": \"string\",\n" + " \"description\": \"pet status in the store\",\n" + " \"enum\": [\n" + " \"available\",\n" + " \"pending\",\n" + " \"sold\"\n" + " ]\n" + " }\n" + " },\n" + " \"xml\": {\n" + " \"name\": \"Pet\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + "}";
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setFlatten(true);
SwaggerParseResult result = new OpenAPIParser().readContents(inputSpec, null, options);
assertTrue(result.getOpenAPI() != null);
}
Aggregations