Skip to content

Commit

Permalink
Merge pull request #451 from swagger-api/non-object-resolve-fully
Browse files Browse the repository at this point in the history
  • Loading branch information
frantuma authored Sep 28, 2023
2 parents 8b83536 + 14444b4 commit 377565c
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,9 @@
</repository>
</repositories>
<properties>
<swagger-core-version>1.6.10</swagger-core-version>
<swagger-parser-version>1.0.65</swagger-parser-version>
<jackson.version>2.14.2</jackson.version>
<swagger-core-version>1.6.11</swagger-core-version>
<swagger-parser-version>1.0.67</swagger-parser-version>
<jackson.version>2.15.2</jackson.version>
<joda-time-version>2.12.2</joda-time-version>
<joda-version>1.9.2</joda-version>
<jetty-version>9.4.51.v20230217</jetty-version>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/io/swagger/inflector/utils/ResolverUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ public Model resolveModel(Model schema) {
LOGGER.debug("not adding recursive properties, using generic object");
model.addProperty(key, new ObjectProperty());
}
} else if (System.getenv("resolveFullySchemaObjectOnly") == null && System.getProperty("resolveFullySchemaObjectOnly") == null){
model.addProperty(key, property);
}
}
return model;
Expand Down
29 changes: 29 additions & 0 deletions src/test/java/io/swagger/test/schema/SchemaValidationTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package io.swagger.test.schema;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.TextNode;
import com.github.fge.jsonschema.core.report.ProcessingReport;
import com.github.fge.jsonschema.main.JsonSchemaFactory;
import io.swagger.inflector.schema.SchemaValidator;
import io.swagger.util.Json;
import io.swagger.util.Yaml;
import org.testng.annotations.Test;

import static org.testng.Assert.assertFalse;
Expand Down Expand Up @@ -96,6 +98,33 @@ public void testValidation() throws Exception {
assertTrue(report.isSuccess());
}

@Test
public void testStringPropertyEnumValidation() throws Exception {
String schemaAsString =
"description: Type of the resource assigned\n" +
"example: api\n" +
"type: string\n" +
"enum:\n" +
" - organization\n" +
" - api\n" +
" - domain\n" +
" - template\n" +
" - team\n" +
" - project\n" +
" - portal-product";
JsonNode schemaObject = Yaml.mapper().readTree(schemaAsString);
JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
com.github.fge.jsonschema.main.JsonSchema schema = factory.getJsonSchema(schemaObject);


JsonNode content = TextNode.valueOf("domain");
ProcessingReport report = schema.validate(content);
assertTrue(report.isSuccess());
content = TextNode.valueOf("domainbad");
report = schema.validate(content);
assertTrue(!report.isSuccess());
}

static class User {
public Long id;
public String name;
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/io/swagger/test/utils/ResolverUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import io.swagger.models.properties.ArrayProperty;
import io.swagger.models.properties.ObjectProperty;
import io.swagger.models.properties.Property;
import io.swagger.models.properties.StringProperty;
import io.swagger.parser.SwaggerParser;
import io.swagger.parser.util.SwaggerDeserializationResult;
import io.swagger.sample.models.Dog;
import io.swagger.util.Json;
import io.swagger.util.Yaml;
Expand Down Expand Up @@ -302,4 +304,13 @@ public void testResolvingWithoutDefinitions() {
Swagger swagger = new SwaggerParser().parse(yaml);
new ResolverUtil().resolveFully(swagger);
}

@Test
public void testStringPropertyResolving() throws Exception {
SwaggerDeserializationResult swaggerParseResult = new SwaggerParser().readWithInfo("./src/test/swagger/string-property-resolving.yaml", null, true);
Swagger swagger = swaggerParseResult.getSwagger();
new ResolverUtil().resolveFully(swagger);
assertTrue(((BodyParameter)swagger.getPath("/orgs/{orgId}/resources").getPost().getParameters().get(1)).getSchema().getProperties().get("type") instanceof StringProperty);
}

}
60 changes: 60 additions & 0 deletions src/test/swagger/string-property-resolving.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
swagger: '2.0'
info:
version: 1.0.8
schemes:
- http
basePath: /access
paths:
'/orgs/{orgId}/resources':
post:
summary: Create a resource
description: >-
Requires system token. Creates a resource for api, domain, organization or team
operationId: addResource
parameters:
- $ref: '#/parameters/orgId'
- in: body
name: resource
required: true
schema:
$ref: '#/definitions/Resource'
responses:
201:
description: Successfully added resource.
parameters:
orgId:
description: Name of the organization.
name: orgId
in: path
type: string
required: true
definitions:
Resource:
type: object
required:
- organization
- name
- type
properties:
organization:
type: string
description: Organization name.
example: MyOrg
name:
type: string
description: Resource name.
example: Accounts API
type:
$ref: '#/definitions/ResourceType'
ResourceType:
description: Type of the resource assigned
example: api
type: string
enum:
- organization
- api
- domain
- template
- team
- project
- portal-product

0 comments on commit 377565c

Please sign in to comment.