Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completely refactor SwaggerResolver to support all sorts of goodness #73

Merged
merged 11 commits into from
Aug 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ target/
.classpath
.project
.settings/
modules/swagger-parser/src/test/resources/relative-file-references/yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

/**
* Core interface for JSON migration
* <p/>
*
* <p>This takes a {@link JsonNode} as an input and outputs the transformed
* {@link JsonNode}.</p>
* <p/>
*
* <p>Note that this interface makes <strong>no guarantee</strong> as to whether
* a <em>new</em> {@code JsonNode} is returned, or the input argument is
* returned (altered or not). If this distinction is important, please document
* it in your implementation(s).</p>
* <p/>
*
* <p>You can either implement this interface directly or use one of the
* predefined migrators in {@link SwaggerMigrators}.</p>
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

/**
* Patch a 1.1 {@code allowableValues} into a 1.2 {@code enum}
* <p/>
*
* <p>{@code allowableValues} is an object which has at least one {@code
* valueType} member, whose value is a JSON String. If this string is {@code
* "LIST"}, then it is replaced by an {@code enum}, as in:</p>
* <p/>
*
* <pre>
* {
* "allowableValues": {
Expand All @@ -27,15 +27,15 @@
* }
* }
* </pre>
* <p/>
*
* <p>which will become:</p>
* <p/>
*
* <pre>
* {
* "enum": [ "a", "b", "c" ]
* }
* </pre>
* <p/>
*
* <p>Another possible value is {@code "range[]"}, however this migrator does
* not handle this case (yet?).</p>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public final class V11ResourceListingMigrator
/**
* Check the validity of a "basePath" argument at the root of a resource
* listing
* <p/>
*
* <p>A {@code basePath} is valid if it obeys the following conditions:</p>
* <p/>
*
* <ul>
* <li>it is an absolute URI;</li>
* <li>its scheme is {@code http} or {@code https};</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@

/**
* Patch a 1.1 dataType into a 1.2 type
* <p/>
*
* <p>Several Swagger objects have the possibility of a data type; as such, JSON
* Schema validation currently cannot really limit the object members present,
* not without the "strictProperties" and "merge" proposals of draft v5.</p>
* <p/>
*
* <p>The schema validation performed is therefore extremely simple: we only
* check that a {@code dataType} field is present, check that its value is one
* of the allowed values, and patch the node.</p>
* <p/>
*
* <p>If {@code dataType} is not a known primitive, it is considered to be a
* v1.2 {@code $ref}.</p>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

/**
* Append a base path to individual API objects
* <p/>
*
* <p>See <a href="/~https://github.com/swagger-api/swagger-parser/issues/4"
* target="_blank">issue #4 on GitHub</a>.</p>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

/**
* A mutable JSON tree with traversal capabilities
* <p/>
*
* <p>Navigation through the tree is done using {@link JsonPointer}s.</p>
* <p/>
*
* <p>Note that {@link JsonNode} is <em>mutable</em>. This means that at init
* time we make a copy of the node given as argument (using {@link
* JsonNode#deepCopy()}, but after that all nodes returned by {@link
* #getCurrentNode()} are mutable. Changes you make to the returned node
* therefore <strong>will</strong> be reflected in the result.</p>
* <p/>
*
* <p>While you can do that, it is advised that you use {@link SwaggerMigrator}s
* instead and make use of the {@link #applyMigrator(SwaggerMigrator)} and
* {@link #applyMigratorToElements(SwaggerMigrator)} methods.</p>
Expand All @@ -48,7 +48,7 @@ public MutableJsonTree(final JsonNode node) {

/**
* Absolute pointer change
* <p/>
*
* <p>The new current node will be the node at this pointer starting from
* the base node.</p>
*
Expand All @@ -62,7 +62,7 @@ public void setPointer(final JsonPointer pointer) {

/**
* Relative pointer change
* <p/>
*
* <p>The pointer in argument is appended to the current pointer (using
* {@link JsonPointer#append(JsonPointer)}) and the current node is set
* accordingly.</p>
Expand All @@ -84,7 +84,7 @@ private void doSetPointer(final JsonPointer pointer) {

/**
* Return the base node
* <p/>
*
* <p>The "base node" here means the (potentially) altered copy of the node
* supplied as the constructor argument.</p>
*
Expand All @@ -105,7 +105,7 @@ public JsonNode getCurrentNode() {

/**
* Apply a JSON Patch to the current node
* <p/>
*
* <p>This will turn the patch into a {@link SwaggerMigrator} using {@link
* SwaggerMigrators#fromPatch(JsonPatch)} and call {@link
* #applyMigrator(SwaggerMigrator)}.</p>
Expand All @@ -121,7 +121,7 @@ public void applyPatch(final JsonPatch patch)

/**
* Apply a migrator to the node at the current pointer
* <p/>
*
* <p>It is assumed here that the current node is a JSON Object.</p>
*
* @param migrator the migrator to apply
Expand Down Expand Up @@ -151,7 +151,7 @@ public void applyMigrator(final SwaggerMigrator migrator)

/**
* Apply a migrator to all elements of the array at the current pointer
* <p/>
*
* <p>Note that if the migrator fails to apply to at least one element, the
* original array is left untouched; its elements are replaced if and only
* if the migrator applies successfully to <strong>all</strong> elements.
Expand All @@ -178,7 +178,7 @@ public void applyMigratorToElements(final SwaggerMigrator migrator)

/**
* Apply a JSON Patch to all elements of a JSON Array
* <p/>
*
* <p>This will wrap the patch into a {@link SwaggerMigrator} using {@link
* SwaggerMigrators#fromPatch(JsonPatch)} and call {@link
* #applyMigratorToElements(SwaggerMigrator)}.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public final class SwaggerMigrators {

/**
* Return a migrator converting object member values to JSON Strings
* <p/>
*
* <p>Note that this will only work if member values are
* <strong>not</strong> containers (ie, JSON Arrays or Objects).</p>
*
Expand All @@ -42,7 +42,7 @@ public static SwaggerMigrator membersToString(
/**
* Return a migrator applying a <a
* href="tools.ietf.org/html/rfc6902">JSON Patch</a>
* <p/>
*
* <p>The JSON Patch must be deserialized at this point. You can also load
* one from the classpath using {@link #patchFromResource(String)}.</p>
*
Expand All @@ -69,7 +69,7 @@ public JsonNode migrate(@Nonnull final JsonNode input)

/**
* Return a migrator renaming object members
* <p/>
*
* <p>Note that this migrator will not fail if the member to rename does not
* exists; however it <strong>will</strong> fail if the <em>target</em>
* member already exists in the target JSON Object.</p>
Expand Down Expand Up @@ -129,9 +129,9 @@ public static SwaggerMigrator patchFromResource(final String resourcePath) {

/**
* Migrator converting object member values to JSON Strings
* <p/>
*
* <p>Important notes:</p>
* <p/>
*
* <ul>
* <li>this migrator will fail if at least one specified member has a
* "container" value (ie, the value is a JSON Array or an Objet);</li>
Expand Down
12 changes: 12 additions & 0 deletions modules/swagger-parser/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@
<packaging>jar</packaging>
<name>swagger-parser</name>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<version>${jmockit-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-core</artifactId>
Expand Down
Loading