question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UUID parameters don't have format "uuid"

See original GitHub issue

I’m using springfox 2.8.0.

The following piece of code:

@RestController
public class NotificationApi {
@ApiOperation(nickname = "markNotificationDelivered", value = "Mark a notification as delivered.")
    @RequestMapping(path = "notifications/{id}/delivered", method = RequestMethod.POST)
    void markNotificationDelivered(@PathVariable("id") UUID id) {

    }
}

is converted to:

"/notifications/{id}/delivered" : {
      "post" : {
        "tags" : [ "notification-api" ],
        "summary" : "Mark a notification as delivered.",
        "operationId" : "markNotificationDelivered",
        "schemes" : [ ],
        "consumes" : [ "application/json" ],
        "produces" : [ "*/*" ],
        "parameters" : [ {
          "name" : "id",
          "in" : "path",
          "description" : "",
          "required" : true,
          "type" : "string"
        } ],
        "responses" : {
          "200" : {
            "description" : "OK",
            "examples" : { },
            "headers" : { }
          }
        },
        "security" : [ ]
      }
    }

The problem is that parameter id doesn’t have "format": "uuid" set. When I annotate the parameter with @ApiParam(format = "uuid") @PathVariable("id"), there is still no format in the Swaggerfile.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
dominik-jastrzebskicommented, Mar 26, 2018

I managed to hotfix this with plugins:

@Component
public class ApiModelPropertyBuilderExtensions implements ModelBuilderPlugin {

    @Override
    public void apply(ModelContext context) {
        Map<String, ModelProperty> updatedProperties =
                modelPropertiesWithUpdatedResolvedTypes(context.getBuilder().build().getProperties());
        context.getBuilder().properties(updatedProperties);
    }

    private Map<String, ModelProperty> modelPropertiesWithUpdatedResolvedTypes(
            Map<String, ModelProperty> originalModelProperties) {
        return originalModelProperties.entrySet().stream().map(entry -> {
            ModelProperty modelProperty = entry.getValue();
            modelProperty.updateModelRef(resolvedType -> {
                if (resolvedType != null && resolvedType.isInstanceOf(UUID.class)) {
                    return new ModelRef("uuid");
                } else {
                    return modelProperty.getModelRef();
                }
            });
            return new AbstractMap.SimpleEntry<>(entry.getKey(), modelProperty);
        }).collect(Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue));
    }

    @Override
    public boolean supports(DocumentationType delimiter) {
        return true;
    }
}
@Component
public class ApiParametersBuilderExtensions implements ParameterBuilderPlugin {

    @Override
    public void apply(ParameterContext parameterContext) {
        ParameterBuilder parameterBuilder = parameterContext.parameterBuilder();
        ResolvedMethodParameter methodParameter = parameterContext.resolvedMethodParameter();
        ResolvedType parameterType = methodParameter.getParameterType();

        if (parameterType.isInstanceOf(UUID.class)) {
            parameterBuilder.modelRef(new ModelRef("uuid"));
        }
    }

    @Override
    public boolean supports(DocumentationType delimiter) {
        return true;
    }
}
1reaction
dilipkrishcommented, Jun 25, 2018

That would be an issue for Swagger-ui

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to define UUID property in JSON Schema and Open API ...
Primitives have an optional modifier property: format . OAS uses several known formats to define in fine detail the data type being used....
Read more >
Guide to UUID in Java - Baeldung
A quick and practical introduction to UUID in Java. ... The UUID class has a single constructor that requires two long parameters describing ......
Read more >
'String' is not convertible to type/format 'String/uuid'
I have tried adding the expression guid() in front of the field in the Flow and still get this error. The 'inputs.parameters' of...
Read more >
Why is java.util.UUID.randomUUID not accepted as a parameter
I have the following function definition: def testGenerateUuids(name: String, uuidFn: () => String, repeats: Int, iterations: Int) { When I call this with:...
Read more >
Universally unique identifier - Wikipedia
Thus, anyone can create a UUID and use it to identify something with near certainty that the identifier does not duplicate one that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found