swagger-api / swagger-api/swagger-codegen
Java client generates models with `String` fields instead of `URL`
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I've generated a Java client ( OkHttp ) from my team's Swagger spec. Everything looks good with the exception that models which have fields defined as url in the spec are generated as Strings.
Ideally we'd like these to be generated as URLs so we get the benefit of type-safety and fail before making a call to our service.
Please point out if this is a non-issue and/or if I'm doing something wrong.
Thanks
Swagger-codegen version
Brew managed: swagger-codegen: stable 2.2.2 (bottled), HEAD
Swagger declaration file content or url
```yaml
hook:
type: string
format: url
description: The webhook endpoint to which notifications are pushed
```
Full sample spec provided here.
Command line used for generation
swagger-codegen generate -i spec-linked-above -l java -o codegen-test/ --api-package com.myco.apackage.name
Steps to reproduce
- Execute the Command line provided directly above
- Look at the
Subscriptionmodel, it has method signatures in the format:public void setHook(String hook)
Related issues
Not that I am aware of
Suggest a Fix
Other data types are implemented as expected (eg: public Integer getIndex()). I hope/expect URL to be treated similarly.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Java generator entry point used by swagger-codegen generate -i ... -l java, then trace how the Swagger type: string, format: url property is mapped into the Subscription model. Reproduce the issue with the linked sample spec and inspect the generated setHook(String hook) signature. Done means URL fields are generated with the intended Java type and the relevant generation behavior is verified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100