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

feat(modify): Allow creating fields #80

Merged
merged 11 commits into from
Jul 24, 2024

Conversation

sandrina-p
Copy link
Collaborator

@sandrina-p sandrina-p commented Jul 18, 2024

Follow-up of #71, scoped on allowing to add new fields

Linear issue (internal)

New specs

Imagine the schema with 2 fields:

const baseSchema = {
  properties: {
    age: {
      title: 'Age',
      type: 'integer',
    },
    family_name: {
      title: 'Family Name',
      type: 'string',
    }
  },
  'x-jsf-order': ['age', 'family_name'],
};

If you want to add a new field to the JSON Schema pass the following config:

const { schema }  = modify(baseSchema, {
  create: {
    username: {
      title: 'Username',
      type: 'string',
    },
  }
)

Which will return the schema:

{
  properties: {
    age: {
      title: 'Age',
      type: 'integer',
    },
    family_name: {
      title: 'Family Name',
      type: 'string',
    },
    username: {
      title: 'Username',
      type: 'string',
    }
  },
  'x-jsf-order': ['age', 'family_name'],
};

Creating an existing field

If you try to create a field that already exists, it get's ignored and it returns a warning.

Here's an example with the age field based on the baseSchema above.

const { schema, warnings } = modify(baseSchema, {
   create: {
     age: { title: "Your age" }
  }
})

console.log(warnings):

[{
  type: "FIELD_TO_CREATE_EXISTS",
  message: `Creating field "age" was ignored because it already exists.`,
}];

Check tests for more examples.

Other features:

@sandrina-p sandrina-p force-pushed the expm-631-jsf-modify-module-allow-adding-new-fields branch from 052fbef to defb1de Compare July 18, 2024 21:46
src/tests/modify.test.js Outdated Show resolved Hide resolved
@sandrina-p sandrina-p changed the title feat(modify): Allow adding new fields feat(modify): Allow creating fields Jul 18, 2024
@sandrina-p sandrina-p self-assigned this Jul 19, 2024
src/tests/modify.test.js Outdated Show resolved Hide resolved
src/modify.js Outdated Show resolved Hide resolved
src/modify.js Outdated Show resolved Hide resolved
danielcardoso5
danielcardoso5 previously approved these changes Jul 24, 2024
danielcardoso5
danielcardoso5 previously approved these changes Jul 24, 2024
@sandrina-p sandrina-p force-pushed the expm-631-jsf-modify-module-allow-adding-new-fields branch from 84e3930 to a33dd02 Compare July 24, 2024 15:36
@sandrina-p sandrina-p merged commit 8a82254 into main Jul 24, 2024
3 checks passed
@sandrina-p sandrina-p deleted the expm-631-jsf-modify-module-allow-adding-new-fields branch July 24, 2024 15:56
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

Successfully merging this pull request may close these issues.

4 participants