Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move inherited properties before sub class properties #89

Open
chris-schra opened this issue Jun 26, 2022 · 0 comments
Open

Move inherited properties before sub class properties #89

chris-schra opened this issue Jun 26, 2022 · 0 comments

Comments

@chris-schra
Copy link

Imagine classes like these

@JSONSchema()
class RichTextSchema extends BaseContentSchema {
  static collectionName: SchemaCollectionName = {
    plural: "RichTexts",
    singular: "RichText",
  };

  @IsOptional()
  @IsString()
  text: string;
}
@JSONSchema()
class TextImageSchema extends RichTextSchema {
  @IsOptional()
  @IsString()
  image: string;
}

By the way "metas" are currently built

    const metas = ownMetas
      .concat(getInheritedMetadatas(target, metadatas))
      .filter(
        (propMeta) =>
          !(
            isExcluded(propMeta, options) ||
            isExcluded({ ...propMeta, target }, options)
          )
      )

Property "image" of sub class TextImageSchema will be output before "text" of parent class RichTextSchema.

I suggest there should be at least an option to be able to output inherited metas before own metas, like

    const allMetas = options.inheritedPropertiesFirst ? 
        getInheritedMetadatas(target, metadatas).concat(ownMetas) : 
        ownMetas.concat(getInheritedMetadatas(target, metadatas))
    
    const metas = allMetas
      .filter(
        (propMeta) =>
          !(
            isExcluded(propMeta, options) ||
            isExcluded({ ...propMeta, target }, options)
          )
      )

In our use case it makes more sense, because we achieve the same "ordering" of properties which helps visualizing them in documentation and react-json-schema-forms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant