use of io.swagger.v3.oas.annotations.headers.Header in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testIssue915.
@Test
public void testIssue915() {
ParseOptions parseOptions = new ParseOptions();
parseOptions.setResolveFully(true);
OpenAPI openAPI = new OpenAPIV3Parser().read("src/test/resources/issue_918.yaml", null, parseOptions);
Map<String, Header> headers = openAPI.getPaths().get("/2.0/users/").getGet().getResponses().get("200").getHeaders();
String description = headers.get("X-Rate-Limit").getDescription();
assertEquals(description, "The number of allowed requests in the current period");
}
use of io.swagger.v3.oas.annotations.headers.Header in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testIssue1177.
@Test
public void testIssue1177(@Injectable final List<AuthorizationValue> auths) {
String path = "/issue-1177/swagger.yaml";
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setResolveFully(true);
OpenAPI openAPI = new OpenAPIV3Parser().readLocation(path, auths, options).getOpenAPI();
// $ref response with $ref header
ApiResponse petsListApiResponse = openAPI.getPaths().get("/update-pets").getPost().getResponses().get("200");
assertNotNull(petsListApiResponse);
Header sessionIdHeader = petsListApiResponse.getHeaders().get("x-session-id");
assertNotNull(sessionIdHeader);
Schema petsListSchema = openAPI.getComponents().getSchemas().get("PetsList");
assertNotNull(petsListSchema);
assertNotNull(openAPI.getComponents().getHeaders());
Header sessionIdHeaderComponent = openAPI.getComponents().getHeaders().get("x-session-id");
assertTrue(sessionIdHeader == sessionIdHeaderComponent);
assertTrue(petsListApiResponse.getContent().get("application/json").getSchema() == petsListSchema);
}
use of io.swagger.v3.oas.annotations.headers.Header 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)"));
}
use of io.swagger.v3.oas.annotations.headers.Header in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method doRelativeFileTest.
private OpenAPI doRelativeFileTest(String location) {
OpenAPIV3Parser parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult readResult = parser.readLocation(location, null, options);
if (readResult.getMessages().size() > 0) {
Json.prettyPrint(readResult.getMessages());
}
final OpenAPI openAPI = readResult.getOpenAPI();
final PathItem path = openAPI.getPaths().get("/health");
// we successfully converted the RefPath to a Path
assertEquals(path.getClass(), PathItem.class);
final List<Parameter> parameters = path.getParameters();
assertParamDetails(parameters, 0, QueryParameter.class, "param1", "query");
assertParamDetails(parameters, 1, HeaderParameter.class, "param2", "header");
final Operation operation = path.getGet();
final List<Parameter> operationParams = operation.getParameters();
assertParamDetails(operationParams, 0, PathParameter.class, "param3", "path");
assertParamDetails(operationParams, 1, HeaderParameter.class, "param4", "header");
final Map<String, ApiResponse> responsesMap = operation.getResponses();
assertResponse(openAPI, responsesMap, "200", "application/json", "Health information from the server", "#/components/schemas/health");
assertResponse(openAPI, responsesMap, "400", "*/*", "Your request was not valid", "#/components/schemas/error");
assertResponse(openAPI, responsesMap, "500", "*/*", "An unexpected error occur during processing", "#/components/schemas/error");
final Map<String, Schema> definitions = openAPI.getComponents().getSchemas();
final Schema refInDefinitions = definitions.get("refInDefinitions");
assertEquals(refInDefinitions.getDescription(), "The example model");
expectedPropertiesInModel(refInDefinitions, "foo", "bar");
final ArraySchema arrayModel = (ArraySchema) definitions.get("arrayModel");
final Schema arrayModelItems = arrayModel.getItems();
assertEquals(arrayModelItems.get$ref(), "#/components/schemas/foo");
final Schema fooModel = definitions.get("foo");
assertEquals(fooModel.getDescription(), "Just another model");
expectedPropertiesInModel(fooModel, "hello", "world");
final ComposedSchema composedCat = (ComposedSchema) definitions.get("composedCat");
final Schema child = composedCat.getAllOf().get(2);
expectedPropertiesInModel(child, "huntingSkill", "prop2", "reflexes", "reflexMap");
final ArraySchema reflexes = (ArraySchema) child.getProperties().get("reflexes");
final Schema reflexItems = reflexes.getItems();
assertEquals(reflexItems.get$ref(), "#/components/schemas/reflex");
assertTrue(definitions.containsKey(reflexItems.get$ref().substring(reflexItems.get$ref().lastIndexOf("/") + 1)));
final Schema reflexMap = (Schema) child.getProperties().get("reflexMap");
final Schema reflexMapAdditionalProperties = (Schema) reflexMap.getAdditionalProperties();
assertEquals(reflexMapAdditionalProperties.get$ref(), "#/components/schemas/reflex");
assertEquals(composedCat.getAllOf().size(), 3);
assertEquals(composedCat.getAllOf().get(0).get$ref(), "#/components/schemas/pet");
assertEquals(composedCat.getAllOf().get(1).get$ref(), "#/components/schemas/foo_1");
return openAPI;
}
use of io.swagger.v3.oas.annotations.headers.Header in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testIssue1644_EmptyValue.
@Test
public void testIssue1644_EmptyValue() 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" + " in: ''\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 not of type `[query|header|path|cookie]`"));
}
Aggregations