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

The attempt to fix recursive schemas causes NPE #15

Closed
dalewking opened this issue Dec 14, 2018 · 2 comments
Closed

The attempt to fix recursive schemas causes NPE #15

dalewking opened this issue Dec 14, 2018 · 2 comments
Labels
0.2.1 bug Something isn't working

Comments

@dalewking
Copy link

Imagine some schemas in components like these where I whittle it down to only enough properties to demonstrate the problem:

Pageable:
  type: object
  properties:
    sort:
      $ref: '#/components/schemas/Sort'
  title: Pageable
Sort:
  type: object
  properties:
    sorted:
      type: boolean
  title: Sort
Page_Foo_:
  type: object
  properties:
    pageable:
      $ref: '#/components/schemas/Pageable'
    sort:
      $ref: '#/components/schemas/Sort'

This causes an NPE because the sort property $ref is not expanded, because #/components/schemas/Sort was seen when expanding Pageable.

@dalewking
Copy link
Author

dalewking commented Dec 14, 2018

Here is a diff that should fix the problem:

diff --git a/src/main/java/io/redskap/swagger/brake/core/model/transformer/SchemaTransformer.java b/src/main/java/io/redskap/swagger/brake/core/model/transformer/SchemaTransformer.java
index eeb1524..2fa60cd 100644
--- a/src/main/java/io/redskap/swagger/brake/core/model/transformer/SchemaTransformer.java
+++ b/src/main/java/io/redskap/swagger/brake/core/model/transformer/SchemaTransformer.java
@@ -46,7 +46,9 @@ public class SchemaTransformer implements Transformer<io.swagger.v3.oas.models.m
         if (isNotBlank(ref) && SeenRefHolder.isNotSeen(ref)) {
             io.swagger.v3.oas.models.media.Schema resolvedSchema = getSchemaForRef(ref);
             SeenRefHolder.store(ref);
-            return internalTransform(resolvedSchema);
+            Schema schema = internalTransform(resolvedSchema);
+            SeenRefHolder.remove(ref);
+            return schema;
         }
 
         Schema.Builder schemaBuilder = new Schema.Builder(swSchema.getType());
@@ -112,6 +114,10 @@ public class SchemaTransformer implements Transformer<io.swagger.v3.oas.models.m
             get().add(refName);
         }
 
+        static void remove(String refName) {
+            get().remove(refName);
+        }
+
         static void clear() {
             HOLDER.remove();
         }

@galovics
Copy link
Member

Fixed.

@galovics galovics added bug Something isn't working 0.3.0 0.2.1 and removed 0.3.0 labels Dec 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.2.1 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants