Skip to content

Commit

Permalink
Merge branch 'bug/3351/fix-issues-with-post'
Browse files Browse the repository at this point in the history
fixes #3351
  • Loading branch information
dilipkrish committed Jul 4, 2020
2 parents 9e64c9f + 2198d9c commit 1e4b753
Show file tree
Hide file tree
Showing 23 changed files with 485 additions and 265 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
import springfox.test.contract.oas.model.Pet;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
Expand Down Expand Up @@ -39,4 +42,11 @@ public void bug3321(
public Mono<ResponseEntity<InputStreamResource>> bug3348(@PathVariable("callId") String callId) {
return null;
}

@PostMapping(path = "/3351/{id}")
public ResponseEntity<String> createPost(
@PathVariable final int id,
@RequestBody final Pet post) {
return ResponseEntity.ok("Success");
}
}
116 changes: 116 additions & 0 deletions oas-contract-tests/src/test/resources/contracts/bugs.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,125 @@
}
}
}
},
"/bugs/3351/{id}": {
"post": {
"tags": [
"bugs-controller"
],
"summary": "createPost",
"operationId": "createPostUsingPOST",
"parameters": [
{
"name": "id",
"in": "path",
"description": "id",
"required": true,
"style": "simple",
"schema": {
"type": "integer",
"format": "int32"
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Pet"
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"type": "string"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"Category": {
"title": "Category",
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"example": 1
},
"name": {
"type": "string",
"example": "Dogs"
}
}
},
"Pet": {
"title": "Pet",
"required": [
"name",
"photoUrls"
],
"type": "object",
"properties": {
"category": {
"$ref": "#/components/schemas/Category"
},
"id": {
"type": "integer",
"format": "int64",
"example": 10
},
"name": {
"type": "string",
"example": "doggie"
},
"photoUrls": {
"type": "array",
"items": {
"type": "string"
}
},
"status": {
"type": "string",
"description": "pet status in the store",
"enum": [
"available",
"pending",
"sold"
]
},
"tags": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Tag"
}
}
}
},
"Tag": {
"title": "Tag",
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
}
}
}
},
"securitySchemes": {
"petstore_auth": {
"type": "oauth2",
Expand Down
25 changes: 0 additions & 25 deletions oas-contract-tests/src/test/resources/contracts/petstore.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,6 @@
"$ref": "#/components/schemas/Pet"
}
},
"application/x-www-form-urlencoded": {
"schema": {
"$ref": "#/components/schemas/Pet"
}
},
"application/xml": {
"schema": {
"$ref": "#/components/schemas/Pet"
Expand Down Expand Up @@ -205,11 +200,6 @@
"$ref": "#/components/schemas/Pet"
}
},
"application/x-www-form-urlencoded": {
"schema": {
"$ref": "#/components/schemas/Pet"
}
},
"application/xml": {
"schema": {
"$ref": "#/components/schemas/Pet"
Expand Down Expand Up @@ -654,11 +644,6 @@
"$ref": "#/components/schemas/Order"
}
},
"application/x-www-form-urlencoded": {
"schema": {
"$ref": "#/components/schemas/Order"
}
},
"application/xml": {
"schema": {
"$ref": "#/components/schemas/Order"
Expand Down Expand Up @@ -790,11 +775,6 @@
"$ref": "#/components/schemas/User"
}
},
"application/x-www-form-urlencoded": {
"schema": {
"$ref": "#/components/schemas/User"
}
},
"application/xml": {
"schema": {
"$ref": "#/components/schemas/User"
Expand Down Expand Up @@ -1057,11 +1037,6 @@
"$ref": "#/components/schemas/User"
}
},
"application/x-www-form-urlencoded": {
"schema": {
"$ref": "#/components/schemas/User"
}
},
"application/xml": {
"schema": {
"$ref": "#/components/schemas/User"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import java.util.Collection;
import java.util.HashSet;
import java.util.Optional;
import java.util.stream.Collectors;

import static org.slf4j.LoggerFactory.*;
Expand All @@ -31,7 +30,7 @@ public ParameterSpecification create(ParameterSpecificationContext context) {
.collect(Collectors.toSet()));
}
if (accepts.isEmpty()) {
accepts.add(MediaType.ALL);
accepts.add(MediaType.APPLICATION_JSON);
}

accepts.stream()
Expand All @@ -47,19 +46,10 @@ public ParameterSpecification create(ParameterSpecificationContext context) {
.model(m -> m.copyOf(simpleParameter.getModel()))
.clearEncodings());
} else if (contentParameter != null) {
Optional<Representation> mediaType = contentParameter.representationFor(each);
context.getContentSpecificationBuilder()
.copyOf(contentParameter)
.requestBody(true)
.representation(each)
.apply(r -> r.model(m -> m.copyOf(mediaType
.map(Representation::getModel)
.orElse(new ModelSpecificationBuilder()
.name(context.getName())
.scalarModel(ScalarType.STRING)
.build())))
.clearEncodings());

contentParameter.representationFor(each)
.ifPresent(representation -> context.getContentSpecificationBuilder()
.representation(representation.getMediaType())
.apply(r -> r.copyOf(representation)));
} else {
LOGGER.warn("Parameter should either be a simple or a content type");
context.getContentSpecificationBuilder()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package springfox.documentation.builders;

import springfox.documentation.schema.CompoundModelSpecification;
import springfox.documentation.schema.ModelKey;
import springfox.documentation.schema.ModelKeyBuilder;
import springfox.documentation.schema.PropertySpecification;
import springfox.documentation.schema.ReferenceModelSpecification;

Expand All @@ -15,22 +15,15 @@
import java.util.stream.Collectors;

public class CompoundModelSpecificationBuilder {
private final ModelSpecificationBuilder parent;
private final Map<String, PropertySpecificationBuilder> properties = new HashMap<>();
private final List<ReferenceModelSpecification> subclassReferences = new ArrayList<>();
private Integer maxProperties;
private Integer minProperties;
private ModelKey modelKey;
private ModelKeyBuilder modelKey;
private String discriminator;

public CompoundModelSpecificationBuilder(ModelSpecificationBuilder parent) {
this.parent = parent;
}

private PropertySpecificationBuilder propertyBuilder(String name) {
return properties.computeIfAbsent(
name,
n -> new PropertySpecificationBuilder(n, this));
return properties.computeIfAbsent(name, PropertySpecificationBuilder::new);
}

public Function<Consumer<PropertySpecificationBuilder>, CompoundModelSpecificationBuilder> property(String name) {
Expand All @@ -40,8 +33,11 @@ public Function<Consumer<PropertySpecificationBuilder>, CompoundModelSpecificati
};
}

public CompoundModelSpecificationBuilder modelKey(ModelKey modelKey) {
this.modelKey = modelKey;
public CompoundModelSpecificationBuilder modelKey(Consumer<ModelKeyBuilder> consumer) {
if (modelKey == null) {
this.modelKey = new ModelKeyBuilder();
}
consumer.accept(modelKey);
return this;
}

Expand All @@ -56,13 +52,12 @@ public CompoundModelSpecificationBuilder minProperties(Integer minProperties) {
}

public CompoundModelSpecification build() {
List<PropertySpecification> properties
= this.properties.values().stream()
.map(PropertySpecificationBuilder::build)
.collect(Collectors.toList());
List<PropertySpecification> properties = this.properties.values().stream()
.map(PropertySpecificationBuilder::build)
.collect(Collectors.toList());
if (modelKey != null) {
return new CompoundModelSpecification(
modelKey,
modelKey.build(),
properties,
maxProperties,
minProperties,
Expand All @@ -76,7 +71,7 @@ public CompoundModelSpecificationBuilder copyOf(CompoundModelSpecification other
if (other == null) {
return this;
}
return modelKey(other.getModelKey())
return modelKey(m -> m.copyOf(other.getModelKey()))
.properties(other.getProperties())
.maxProperties(other.getMaxProperties())
.minProperties(other.getMinProperties())
Expand All @@ -85,28 +80,26 @@ public CompoundModelSpecificationBuilder copyOf(CompoundModelSpecification other
}

public CompoundModelSpecificationBuilder properties(Collection<PropertySpecification> properties) {
properties.forEach(each -> {
this.property(each.getName())
.apply(p -> {
p.type(each.getType())
.allowEmptyValue(each.getAllowEmptyValue())
.defaultValue(each.getDefaultValue())
.deprecated(each.getDeprecated())
.description(each.getDescription())
.example(each.getExample())
.isHidden(each.getHidden())
.nullable(each.getNullable())
.position(each.getPosition())
.readOnly(each.getReadOnly())
.required(each.getRequired())
.vendorExtensions(each.getVendorExtensions())
.xml(each.getXml())
.writeOnly(each.getWriteOnly());
each.getFacets()
.forEach(f -> p.facetBuilder(f.facetBuilder())
.copyOf(f));
});
});
properties.forEach(each -> this.property(each.getName())
.apply(p -> {
p.type(each.getType())
.allowEmptyValue(each.getAllowEmptyValue())
.defaultValue(each.getDefaultValue())
.deprecated(each.getDeprecated())
.description(each.getDescription())
.example(each.getExample())
.isHidden(each.getHidden())
.nullable(each.getNullable())
.position(each.getPosition())
.readOnly(each.getReadOnly())
.required(each.getRequired())
.vendorExtensions(each.getVendorExtensions())
.xml(each.getXml())
.writeOnly(each.getWriteOnly());
each.getFacets()
.forEach(f -> p.facetBuilder(f.facetBuilder())
.copyOf(f));
}));
return this;
}

Expand Down

0 comments on commit 1e4b753

Please sign in to comment.