use of io.swagger.v3.oas.models.security.SecurityScheme.In in project swagger-parser by swagger-api.
the class NetworkReferenceTest method testValidateExternalRefsTrueRemote.
@Test(description = "option true, adds Original Location to messages when ref is remote")
public void testValidateExternalRefsTrueRemote() throws Exception {
ParseOptions options = new ParseOptions();
options.setValidateExternalRefs(true);
options.setResolve(true);
new Expectations() {
{
remoteUrl.urlToString("http://localhost:8080/swos-443/root.yaml", new ArrayList<>());
result = issue_443_yaml;
remoteUrl.urlToString("http://localhost:8080/swos-443/ref.yaml", new ArrayList<>());
result = issue_443_ref_yaml;
}
};
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("http://localhost:8080/swos-443/root.yaml", null, options);
OpenAPI openAPI = result.getOpenAPI();
assertNotNull(result.getMessages());
assertEquals(result.getMessages().size(), 19);
assertNotNull(openAPI);
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"));
}
use of io.swagger.v3.oas.models.security.SecurityScheme.In in project swagger-parser by swagger-api.
the class SchemaProcessor method processReferenceSchema.
private void processReferenceSchema(Schema schema) {
/* if this is a URL or relative ref:
1) we need to load it into memory.
2) shove it into the #/components/schemas
3) update the RefModel to point to its location in #/components/schemas
*/
RefFormat refFormat = computeRefFormat(schema.get$ref());
String $ref = schema.get$ref();
if (isAnExternalRefFormat(refFormat)) {
final String newRef = externalRefProcessor.processRefToExternalSchema($ref, refFormat);
if (newRef != null) {
schema.set$ref(RefType.SCHEMAS.getInternalPrefix() + newRef);
}
}
}
use of io.swagger.v3.oas.models.security.SecurityScheme.In in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method testParameterOnPathLevel.
@Test
public void testParameterOnPathLevel() throws Exception {
String yaml = "openapi: 3.0.1\n" + "info:\n" + " version: '1.0.0'\n" + " title: 'title'\n" + " description: 'description'\n" + "paths:\n" + " /foo:\n" + " parameters:\n" + " - in: query\n" + " name: bar\n" + " schema:\n" + " type: string\n" + " get:\n" + " responses:\n" + " '200':\n" + " description: OK";
ParseOptions options = new ParseOptions();
options.setResolve(true);
OpenAPI openAPI = new OpenAPIV3Parser().readContents(yaml, null, options).getOpenAPI();
assertNotNull(openAPI);
List<Parameter> getParameters = openAPI.getPaths().get("/foo").getGet().getParameters();
assertNotNull(getParameters);
assertEquals(1, getParameters.size());
assertEquals("bar", getParameters.get(0).getName());
}
use of io.swagger.v3.oas.models.security.SecurityScheme.In in project swagger-parser by swagger-api.
the class InlineModelResolverTest method testSkipInlineMatchesFalse.
@Test
public void testSkipInlineMatchesFalse() {
final OpenAPI openAPI = new OpenAPI();
final InlineModelResolver inlineModelResolver = new InlineModelResolver();
final Schema operationAlphaInAsset = new ObjectSchema();
operationAlphaInAsset.setTitle("operationAlphaInAsset");
operationAlphaInAsset.addProperties("id1", new IntegerSchema());
operationAlphaInAsset.addProperties("id2", new IntegerSchema());
final Schema operationAlphaIn = new ObjectSchema();
operationAlphaIn.setTitle("operationAlphaIn");
operationAlphaIn.addProperties("asset", operationAlphaInAsset);
final Schema operationAlphaRequest = new ObjectSchema();
operationAlphaRequest.setTitle("operationAlphaRequest");
operationAlphaRequest.addProperties("in", operationAlphaIn);
final Schema operationBetaInAsset = new ObjectSchema();
operationBetaInAsset.setTitle("operationBetaInAsset");
operationBetaInAsset.addProperties("id1", new IntegerSchema());
operationBetaInAsset.addProperties("id2", new IntegerSchema());
final Schema operationBetaIn = new ObjectSchema();
operationBetaIn.setTitle("operationBetaIn");
operationBetaIn.addProperties("asset", operationBetaInAsset);
final Schema operationBetaRequest = new ObjectSchema();
operationBetaRequest.setTitle("operationBetaRequest");
operationBetaRequest.addProperties("in", operationBetaIn);
openAPI.path("/operationAlpha", new PathItem().get(new Operation().requestBody(new RequestBody().content(new Content().addMediaType("*/*", new MediaType().schema(operationAlphaRequest))))));
openAPI.path("/operationBeta", new PathItem().get(new Operation().requestBody(new RequestBody().content(new Content().addMediaType("*/*", new MediaType().schema(operationBetaRequest))))));
inlineModelResolver.flatten(openAPI);
assertNotNull(openAPI);
assertNotNull(openAPI.getComponents());
assertNotNull(openAPI.getComponents().getSchemas());
assertEquals(openAPI.getComponents().getSchemas().size(), 6);
}
use of io.swagger.v3.oas.models.security.SecurityScheme.In 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");
}
Aggregations