Skip to content

[REQ] Convert StringSchema with format "uri-reference" to java.net.URI instead if java.lang.String in Java client Codegenerator #24012

@VadimKobyakov

Description

@VadimKobyakov

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).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions