Skip to content

Commit

Permalink
Merge pull request #1977 from swagger-api/revert-1956-bugfix-1955
Browse files Browse the repository at this point in the history
Revert "Bugfix 1955 Schema refs of array parameters are not resolved for renamed schema components"
  • Loading branch information
gracekarina authored Sep 23, 2023
2 parents 5108367 + 0110632 commit d2e6b3a
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ else if(model.getProperties() != null) {
for(String key : properties.keySet()) {
Schema property = properties.get(key);
if (property != null) {
updateRefs(property, "");
updateRefs(property, pathRef);
}
}
}
Expand All @@ -254,22 +254,22 @@ else if(model instanceof ComposedSchema) {
ComposedSchema composedSchema = (ComposedSchema) model;
if (composedSchema.getAllOf() != null) {
for (Schema innerModel : composedSchema.getAllOf()) {
updateRefs(innerModel, "");
updateRefs(innerModel, pathRef);
}
}if (composedSchema.getAnyOf() != null) {
for(Schema innerModel : composedSchema.getAnyOf()) {
updateRefs(innerModel, "");
updateRefs(innerModel, pathRef);
}
}if (composedSchema.getOneOf() != null) {
for (Schema innerModel : composedSchema.getOneOf()) {
updateRefs(innerModel, "");
updateRefs(innerModel, pathRef);
}
}
}
else if(model instanceof ArraySchema) {
ArraySchema arraySchema = (ArraySchema) model;
if(arraySchema.getItems() != null) {
updateRefs(arraySchema.getItems(), "");
updateRefs(arraySchema.getItems(), pathRef);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,13 @@
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.PathItem;
import io.swagger.v3.oas.models.PathItem.HttpMethod;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.parameters.Parameter;
import io.swagger.v3.parser.OpenAPIV3Parser;
import io.swagger.v3.parser.core.models.ParseOptions;
import io.swagger.v3.parser.core.models.SwaggerParseResult;
import org.testng.annotations.Test;

import java.net.URL;
import java.util.Map.Entry;
import java.util.Objects;

import static java.lang.String.format;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;

public class PathsProcessorTest {

Expand Down Expand Up @@ -49,36 +42,6 @@ public void testProcessPaths_parameters_refOperationLevelDefinition() {
assertOperationsHasParameters(openAPI, "/ref/test/{id}/operationlevelparam");
}

@Test
public void testProcessPaths_refsToRenamedSchemasResolved() {
URL mergeSpecLocation = getClass().getClassLoader().getResource("issue-1955/merged_spec12.yaml");
Objects.requireNonNull(mergeSpecLocation);
ParseOptions parseOptions = new ParseOptions();
parseOptions.setResolve(true);

SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(mergeSpecLocation.toString(), null, parseOptions);

swaggerParseResult.getOpenAPI()
.getPaths().values().stream()
.flatMap(path -> path.readOperationsMap().values().stream())
.flatMap(operation -> operation.getParameters().stream())
.map(Parameter::getSchema)
.forEach(this::assertSchemaNoExternalRefs);
}

private void assertSchemaNoExternalRefs(Schema<?> schema) {
if (schema.get$ref() != null) {
assertSchemaRefInternal(schema.get$ref());
}
if (schema.getItems() != null && schema.getItems().get$ref() != null) {
assertSchemaRefInternal(schema.getItems().get$ref());
}
}

private void assertSchemaRefInternal(String ref) {
assertTrue(ref.startsWith("#"));
}

private void assertOperationsHasParameters(OpenAPI openAPI, String path) {
PathItem pathItem = openAPI.getPaths().get(path);

Expand All @@ -91,4 +54,4 @@ private void assertOperationsHasParameters(OpenAPI openAPI, String path) {
assertFalse(operation.getParameters() == null || operation.getParameters().isEmpty(), format("Expected parameters on %s operation for %s but found none", httpMethod, path));
}
}
}
}

This file was deleted.

32 changes: 0 additions & 32 deletions modules/swagger-parser-v3/src/test/resources/issue-1955/spec1.yaml

This file was deleted.

32 changes: 0 additions & 32 deletions modules/swagger-parser-v3/src/test/resources/issue-1955/spec2.yaml

This file was deleted.

5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@
<artifactId>surefire-junit4</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng-version}</version>
</dependency>
</dependencies>
<configuration>
<testNGArtifactName>none:none</testNGArtifactName>
Expand Down

0 comments on commit d2e6b3a

Please sign in to comment.