OpenAPITools / OpenAPITools/openapi-generator
[REQ] Convert StringSchema with format "uri-reference" to java.net.URI instead if java.lang.String in Java client Codegenerator
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Is your feature request related to a problem? Please describe.
When converting a Schema formatted as a String Type and With Uri-Reference Format, like so:
my-reference:
type: string
format: uri-reference
The Java Client Codegenerator converts it to a String Object.
Describe the solution you'd like
The Java Documentation on java.net.URI describes that the URI Object in Java may also be a non-absolute URI, like the OpenApi Format regsitry and RFC 3986 describe it. It would therefore be nice if A String Schema with "uri-reference" format would convert to java.net.URI, just like A String Schema with format "uri" already does
Additional Context
Suggestion
There is a Method in ModelUtils.java that checks a Schema if it is a UriSchema:
public static boolean isURISchema(Schema schema) {
// format: uri
return SchemaTypeUtil.STRING_TYPE.equals(getType(schema))
&& URI_FORMAT.equals(schema.getFormat());
}
And is used by AbstractJavaCodegen.java in toDefaultValue (line 1451):
else if (ModelUtils.isURISchema(schema)) {
if (schema.getDefault() != null) {
return "URI.create(\"" + escapeText(String.valueOf(schema.getDefault())) + "\")";
}
return null;
}
and (line 1540):
else if(ModelUtils.isURISchema(propertySchema)) {
defaultPropertyExpression = "java.net.URI.create(\"" + escapeText(value.asText()) + "\")";
}
for those two uses a new method isUriReferenceSchema(Schema schema) might be introduced to set both checks to ModelUtils.isURISchema(schema)) || ModelUtils.isUriReferenceSchema(schema). This might allow sufficient generation (I am not 100% sure i only skimmed the source code).
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 ModelUtils.java and AbstractJavaCodegen.java, especially isURISchema, toDefaultValue, and the property default-expression handling described in the issue. Inspect existing Java client generator tests for URI formatting, then verify that a string schema with format "uri-reference" generates java.net.URI and handles default values consistently with "uri".
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100