Skip to content

Class naming for array elements #29

@gertvv

Description

@gertvv

I'm unable to set singular class names for elements of arrays. This might just be a documentation issue. I have tried the following. Schema:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "outcomes": {
      "type": "array",
      "items": {
        "$id": "outcome",
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          }
        }
      }
    }
  }
}

And package-info:

@GenerateRecordsFromJsonSchemas(
  schemaRootFileLocations =
  @JsonSchemaFileLocation(
    moduleAndPackage = "com.example",
    relativeName = "my-schema.json"
  ),
  schemaConfigurations = {
    @JsonSchemaConfiguration(
      schemaId = "outcome",
      javaTypeQualifiedName = "com.example.Outcome"
    )
  }
)
package org.cochrane.datatransfer;

import com.cosium.json_schema_to_java_record_api.GenerateRecordsFromJsonSchemas;
import com.cosium.json_schema_to_java_record_api.JsonSchemaConfiguration;
import com.cosium.json_schema_to_java_record_api.JsonSchemaFileLocation;

Based on the README I had expected this to work. I also tried putting the Outcome under a definitions property and referring to it by $ref. While either way parse and generate OK, the configuration is not being applied. I have also tried with and without the brackets ({}) around the @JsonSchemaConfiguration.

I've further tried to assign a $id to the top-level schema and referring to it like <id>#/definitions/Outcome but that also didn't work. And finally I've tried nested schemas within $defs as well without success.

If the only way to handle this is to put schemas in separate files and refer to them via classpath URLs that would be disappointing because I'd like to be able to publish the schema without reference to any Java-isms.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions