use of io.swagger.v3.parser.OpenAPIResolver in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testDeserializeBinaryString.
@Test
public void testDeserializeBinaryString() {
String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + " title: foo\n" + " version: ''\n" + "paths:\n" + " /test:\n" + " post:\n" + " responses:\n" + " '200':\n" + " description: ok\n" + " requestBody:\n" + " content:\n" + " application/json:\n" + " schema:\n" + " type: string\n" + " format: binary";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(yaml, null, null);
final OpenAPI resolved = new OpenAPIResolver(result.getOpenAPI(), null).resolve();
assertTrue(resolved.getPaths().get("/test").getPost().getRequestBody().getContent().get("application/json").getSchema() instanceof BinarySchema);
}
use of io.swagger.v3.parser.OpenAPIResolver in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testDeserializeDateTimeString.
@Test
public void testDeserializeDateTimeString() {
String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + " version: 0.0.0\n" + " title: My Title\n" + "paths:\n" + " /persons:\n" + " get:\n" + " description: a test\n" + " responses:\n" + " '200':\n" + " description: Successful response\n" + " content:\n" + " '*/*':\n" + " schema:\n" + " type: object\n" + " properties:\n" + " dateTime:\n" + " $ref: '#/components/schemas/DateTimeString'\n" + "components:\n" + " schemas:\n" + " DateTimeString:\n" + " type: string\n" + " format: date-time\n" + " default: 2019-01-01T00:00:00Z\n" + " enum:\n" + " - null\n" + " - Nunh uh\n" + " - 2019-01-01T00:00:00Z\n" + " - 2018-02-02T23:59:59.999-05:00\n" + " - 2017-03-03T11:22:33+06:00\n" + " - 2016-04-04T22:33:44.555Z\n" + "";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(yaml, null, null);
final OpenAPI resolved = new OpenAPIResolver(result.getOpenAPI(), null).resolve();
Schema dateTimeModel = resolved.getComponents().getSchemas().get("DateTimeString");
assertTrue(dateTimeModel instanceof DateTimeSchema);
List<OffsetDateTime> dateTimeValues = dateTimeModel.getEnum();
assertEquals(dateTimeValues.size(), 5);
assertEquals(dateTimeValues.get(0), null);
assertEquals(dateTimeValues.get(1), OffsetDateTime.of(2019, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC));
assertEquals(dateTimeValues.get(2), OffsetDateTime.of(2018, 2, 2, 23, 59, 59, 999000000, ZoneOffset.ofHours(-5)));
assertEquals(dateTimeValues.get(3), OffsetDateTime.of(2017, 3, 3, 11, 22, 33, 0, ZoneOffset.ofHours(6)));
assertEquals(dateTimeValues.get(4), OffsetDateTime.of(2016, 4, 4, 22, 33, 44, 555000000, ZoneOffset.UTC));
assertEquals(dateTimeModel.getDefault(), OffsetDateTime.of(2019, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC));
assertEquals(result.getMessages(), Arrays.asList("attribute components.schemas.DateTimeString.enum=`Nunh uh` is not of type `date-time`"));
}
use of io.swagger.v3.parser.OpenAPIResolver in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method testYamlArrayResponseRemoteRefs.
@Test(description = "resolve array response remote refs in yaml")
public void testYamlArrayResponseRemoteRefs() {
final OpenAPI swagger = new OpenAPI();
swagger.path("/fun", new PathItem().get(new Operation().responses(new ApiResponses().addApiResponse("200", new ApiResponse().content(new Content().addMediaType("*/*", new MediaType().schema(new ArraySchema().items(new Schema().$ref(replacePort(REMOTE_REF_YAML))))))))));
final OpenAPI resolved = new OpenAPIResolver(swagger, null).resolve();
final ApiResponse response = swagger.getPaths().get("/fun").getGet().getResponses().get("200");
final ArraySchema array = (ArraySchema) response.getContent().get("*/*").getSchema();
assertNotNull(array.getItems());
assertEquals(array.getItems().get$ref(), "#/components/schemas/Tag");
assertNotNull(swagger.getComponents().getSchemas().get("Tag"));
}
use of io.swagger.v3.parser.OpenAPIResolver in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method testOperationParameterRemoteRefs.
@Test(description = "resolve operation parameter remote refs")
public void testOperationParameterRemoteRefs() {
final OpenAPI swagger = new OpenAPI();
List<Parameter> parameters = new ArrayList<>();
parameters.add(new Parameter().$ref("#/components/parameters/SampleParameter"));
swagger.path("/fun", new PathItem().get(new Operation().parameters(parameters)));
swagger.components(new Components().addParameters("SampleParameter", new QueryParameter().name("skip").schema(new IntegerSchema())));
final OpenAPI resolved = new OpenAPIResolver(swagger, null).resolve();
final List<Parameter> params = swagger.getPaths().get("/fun").getGet().getParameters();
assertEquals(params.size(), 1);
final Parameter param = params.get(0);
assertEquals(param.getName(), "skip");
}
use of io.swagger.v3.parser.OpenAPIResolver in project swagger-parser by swagger-api.
the class OpenAPIResolverTest method testMapRemoteModelProperty.
private void testMapRemoteModelProperty(String remoteRef) {
final OpenAPI swagger = new OpenAPI();
swagger.components(new Components().addSchemas("Sample", new Schema().addProperties("remoteRef", new Schema().additionalProperties(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.getAdditionalProperties() != null);
assertEquals(((Schema) prop.getAdditionalProperties()).get$ref(), "#/components/schemas/Tag");
assertNotNull(swagger.getComponents().getSchemas().get("Tag"));
}
Aggregations