use of io.swagger.v3.core.util.Yaml in project swagger-core by swagger-api.
the class EnumPropertyTest method testEnumRefPropertyGlobalNotAffectingNonEnums.
@Test(description = "it should not affect non-enum models when the enumsAsRef property is enabled globally")
public void testEnumRefPropertyGlobalNotAffectingNonEnums() {
ModelResolver.enumsAsRef = true;
Schema schema = context.resolve(new AnnotatedType(Model1979.class));
final Map<String, Schema> models = context.getDefinedModels();
final String yaml = "Model1979:\n" + " type: object\n" + " properties:\n" + " id:\n" + " type: string\n" + " nullable: true";
SerializationMatchers.assertEqualsToYaml(models, yaml);
ModelResolver.enumsAsRef = false;
}
use of io.swagger.v3.core.util.Yaml in project swagger-core by swagger-api.
the class EnumPropertyTest method testEnumRefPropertyWithFQNTypeNameResolver.
@Test(description = "it should read a model with an enum property as a reference with fqn TypeNameResolver")
public void testEnumRefPropertyWithFQNTypeNameResolver() {
TypeNameResolver.std.setUseFqn(true);
Schema schema = context.resolve(new AnnotatedType(ModelWithEnumRefProperty.class));
final Map<String, Schema> models = context.getDefinedModels();
final String yaml = "io.swagger.v3.core.oas.models.ModelWithEnumRefProperty:\n" + " type: object\n" + " properties:\n" + " a:\n" + " $ref: '#/components/schemas/io.swagger.v3.core.oas.models.TestEnum'\n" + " b:\n" + " $ref: '#/components/schemas/io.swagger.v3.core.oas.models.TestEnum'\n" + " c:\n" + " $ref: '#/components/schemas/io.swagger.v3.core.oas.models.TestSecondEnum'\n" + " d:\n" + " type: string\n" + " enum:\n" + " - A_PRIVATE\n" + " - A_PUBLIC\n" + " - A_SYSTEM\n" + " - A_INVITE_ONLY\n" + "io.swagger.v3.core.oas.models.TestEnum:\n" + " type: string\n" + " enum:\n" + " - PRIVATE\n" + " - PUBLIC\n" + " - SYSTEM\n" + " - INVITE_ONLY\n" + "io.swagger.v3.core.oas.models.TestSecondEnum:\n" + " type: string\n" + " enum:\n" + " - A_PRIVATE\n" + " - A_PUBLIC\n" + " - A_SYSTEM\n" + " - A_INVITE_ONLY\n";
TypeNameResolver.std.setUseFqn(false);
SerializationMatchers.assertEqualsToYaml(models, yaml);
}
use of io.swagger.v3.core.util.Yaml in project swagger-core by swagger-api.
the class ParameterDeSerializationTest method testIssue1765.
@Test(description = "should serialize correctly typed numeric enums")
public void testIssue1765() throws Exception {
String yaml = "openapi: '3.0.1'\n" + "paths:\n" + " /test:\n" + " get:\n" + " parameters:\n" + " - name: \"days\"\n" + " in: \"path\"\n" + " required: true\n" + " schema:\n" + " type: \"integer\"\n" + " format: \"int32\"\n" + " enum:\n" + " - 1\n" + " - 2\n" + " - 3\n" + " - 4\n" + " - 5\n" + " responses:\n" + " default:\n" + " description: great";
OpenAPI swagger = Yaml.mapper().readValue(yaml, OpenAPI.class);
SerializationMatchers.assertEqualsToYaml(swagger, yaml);
}
use of io.swagger.v3.core.util.Yaml in project swagger-core by swagger-api.
the class JsonDeserializationTest method testNullEnumItem.
@Test(description = "Deserialize null enum item")
public void testNullEnumItem() throws Exception {
String yaml = "openapi: 3.0.1\n" + "paths:\n" + " /:\n" + " get:\n" + " tags:\n" + " - MyTag\n" + " summary: Operation Summary\n" + " description: Operation Description\n" + " operationId: operationId\n" + " parameters:\n" + " - name: subscriptionId\n" + " in: query\n" + " schema:\n" + " type: string\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " '*/*': {}\n" + "components:\n" + " schemas:\n" + " UserStatus:\n" + " type: integer\n" + " description: some int values with null\n" + " format: int32\n" + " enum:\n" + " - 1\n" + " - 2\n" + " - null\n";
OpenAPI oas = Yaml.mapper().readValue(yaml, OpenAPI.class);
assertEquals(oas.getComponents().getSchemas().get("UserStatus").getEnum(), Arrays.asList(1, 2, null));
yaml = "openapi: 3.0.1\n" + "paths:\n" + " /:\n" + " get:\n" + " tags:\n" + " - MyTag\n" + " summary: Operation Summary\n" + " description: Operation Description\n" + " operationId: operationId\n" + " parameters:\n" + " - name: subscriptionId\n" + " in: query\n" + " schema:\n" + " type: string\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " '*/*': {}\n" + "components:\n" + " schemas:\n" + " UserStatus:\n" + " type: string\n" + " description: some int values with null\n" + " enum:\n" + " - 1\n" + " - 2\n" + " - null\n";
oas = Yaml.mapper().readValue(yaml, OpenAPI.class);
assertEquals(oas.getComponents().getSchemas().get("UserStatus").getEnum(), Arrays.asList("1", "2", null));
}
use of io.swagger.v3.core.util.Yaml in project swagger-core by swagger-api.
the class OpenAPI3_1DeserializationTest method deserializePetstore3_0.
@Test
public void deserializePetstore3_0() throws IOException {
final String jsonString = ResourceUtils.loadClassResource(getClass(), "specFiles/petstore-3.0.yaml");
final OpenAPI swagger = Yaml.mapper().readValue(jsonString, OpenAPI.class);
assertNotNull(swagger);
assertEquals(swagger.getInfo().getLicense().getIdentifier(), null);
}
Aggregations