use of io.swagger.v3.oas.annotations.media.Schema in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method testSimpleRemoteModelProperty.
private void testSimpleRemoteModelProperty(String remoteRef) {
final OpenAPI swagger = new OpenAPI();
swagger.components(new Components().addSchemas("Sample", new Schema().addProperties("remoteRef", new Schema().$ref(remoteRef))));
final OpenAPI resolved = new OpenAPIResolver(swagger, null).resolve();
final Schema prop = (Schema) resolved.getComponents().getSchemas().get("Sample").getProperties().get("remoteRef");
assertTrue(prop.get$ref() != null);
assertEquals(prop.get$ref(), "#/components/schemas/Tag");
assertNotNull(swagger.getComponents().getSchemas().get("Tag"));
}
use of io.swagger.v3.oas.annotations.media.Schema 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.annotations.media.Schema in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method propertyNameMixup.
@Test
public void propertyNameMixup() {
ParseOptions parseOptions = new ParseOptions();
parseOptions.setResolveFully(true);
OpenAPI openAPI = new OpenAPIV3Parser().read("simple.yaml", null, parseOptions);
assertEquals(((StringSchema) openAPI.getComponents().getSchemas().get("Manufacturer").getProperties().get("name")).getExample(), "ACME Corporation");
Schema schema = openAPI.getPaths().get("/inventory").getGet().getResponses().get("200").getContent().get("application/json").getSchema();
assertEquals(((ObjectSchema) ((ArraySchema) schema).getItems().getProperties().get("manufacturer")).getProperties().get("name").getExample(), "ACME Corporation");
}
use of io.swagger.v3.oas.annotations.media.Schema in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method testIssue1157.
@Test
public void testIssue1157(@Injectable final List<AuthorizationValue> auths) {
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setResolveFully(true);
OpenAPI openAPIAnyOf = new OpenAPIV3Parser().readLocation("/issue-1157/anyOf-example.yaml", auths, options).getOpenAPI();
Schema petSchemaAnyOf = openAPIAnyOf.getComponents().getSchemas().get("Pet");
assertTrue(petSchemaAnyOf instanceof ComposedSchema);
assertTrue(((ComposedSchema) petSchemaAnyOf).getAnyOf() != null);
OpenAPI openAPIOneOf = new OpenAPIV3Parser().readLocation("/issue-1157/oneOf-example.yaml", auths, options).getOpenAPI();
Schema petSchemaOneOf = openAPIOneOf.getComponents().getSchemas().get("Pet");
assertTrue(petSchemaOneOf instanceof ComposedSchema);
assertTrue(((ComposedSchema) petSchemaOneOf).getOneOf() != null);
OpenAPI openAPIAllOf = new OpenAPIV3Parser().readLocation("/issue-1157/allOf-example.yaml", auths, options).getOpenAPI();
Schema petSchemaAllOf = openAPIAllOf.getComponents().getSchemas().get("Pet");
assertFalse(petSchemaAllOf instanceof ComposedSchema);
assertTrue(petSchemaAllOf.getProperties() != null);
}
use of io.swagger.v3.oas.annotations.media.Schema in project swagger-parser by swagger-api.
the class ExternalRefProcessorTest method testProcessRefToExternalDefinition_NoNameConflict.
@Test
public void testProcessRefToExternalDefinition_NoNameConflict(@Injectable final Schema mockedModel) throws Exception {
final String ref = "http://my.company.com/path/to/file.json#/foo/bar";
final RefFormat refFormat = RefFormat.URL;
new StrictExpectations() {
{
cache.getRenamedRef(ref);
times = 1;
result = null;
cache.loadRef(ref, refFormat, Schema.class);
times = 1;
result = mockedModel;
openAPI.getComponents();
times = 1;
result = new Components();
openAPI.getComponents().getSchemas();
times = 1;
result = null;
cache.putRenamedRef(ref, "bar");
openAPI.getComponents().addSchemas("bar", mockedModel);
times = 1;
cache.addReferencedKey("bar");
times = 1;
result = null;
}
};
String newRef = new ExternalRefProcessor(cache, openAPI).processRefToExternalSchema(ref, refFormat);
assertEquals(newRef, "bar");
}
Aggregations