-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'bug/2767/example-not-working'
fixes #2767
- Loading branch information
Showing
13 changed files
with
441 additions
and
55 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
oas-contract-tests/src/main/java/springfox/test/contract/oas/bugs/Bug2767.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package springfox.test.contract.oas.bugs; | ||
|
||
import io.swagger.annotations.ApiModelProperty; | ||
|
||
public class Bug2767 { | ||
public static class ErrorResponse { | ||
@ApiModelProperty(required = true, example = "address") | ||
private String invalidField; | ||
|
||
public String getInvalidField() { | ||
return invalidField; | ||
} | ||
|
||
public void setInvalidField(String invalidField) { | ||
this.invalidField = invalidField; | ||
} | ||
} | ||
|
||
public static class Response { | ||
@ApiModelProperty(required = true, example = "some data") | ||
private String data; | ||
|
||
public String getData() { | ||
return data; | ||
} | ||
|
||
public void setData(String data) { | ||
this.data = data; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,6 +121,6 @@ public Example build() { | |
description, | ||
value, | ||
externalValue, | ||
mediaType); | ||
emptyToNull(mediaType)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 12 additions & 4 deletions
16
springfox-oas/src/main/java/springfox/documentation/oas/mappers/ExamplesMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,38 @@ | ||
package springfox.documentation.oas.mappers; | ||
|
||
import org.mapstruct.AfterMapping; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
import org.mapstruct.MappingTarget; | ||
import org.mapstruct.Mappings; | ||
import springfox.documentation.schema.Example; | ||
|
||
import java.util.Collection; | ||
import java.util.Map; | ||
import java.util.TreeMap; | ||
|
||
import static springfox.documentation.builders.BuilderDefaults.*; | ||
|
||
@Mapper(componentModel = "spring", uses = VendorExtensionsMapper.class) | ||
public interface ExamplesMapper { | ||
default Map<String, io.swagger.v3.oas.models.examples.Example> mapExamples(Collection<Example> from) { | ||
Map<String, io.swagger.v3.oas.models.examples.Example> examples = new TreeMap<>(); | ||
for (Example each : from) { | ||
examples.put( | ||
each.getMediaType().orElse(""), | ||
each.getId(), | ||
toOasExample(each)); | ||
} | ||
return examples; | ||
} | ||
|
||
@AfterMapping | ||
default void afterMappingParameter( | ||
Example from, | ||
@MappingTarget io.swagger.v3.oas.models.examples.Example target) { | ||
target.extensions(new VendorExtensionsMapper().mapExtensions(from.getExtensions())); | ||
} | ||
|
||
@Mappings({ | ||
@Mapping(target = "$ref", ignore = true) | ||
@Mapping(target = "$ref", ignore = true), | ||
@Mapping(target = "extensions", ignore = true) | ||
}) | ||
io.swagger.v3.oas.models.examples.Example toOasExample(Example from); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.