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 picking fields #79

Merged
merged 8 commits into from
Jul 25, 2024

Conversation

sandrina-p
Copy link
Collaborator

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

Follow-up of #71, scoped on allowing to pick certain fields

Linear issue (internal)

New specs

Imagine the schema below with 4 fields to buy tickets:

const schemaTickets = {
  properties: {
    age: {
      title: 'Age',
      type: 'integer',
    },
    quantity: {
      title: 'Quantity',
      type: 'integer',
    },
    has_premium: {
      title: 'Has premium',
      type: 'string',
    },
    premium_id: {
      title: 'Premium ID',
      type: 'boolean',
    },
  },
  'x-jsf-order': ['age', 'quantity', 'has_premium', 'premium_id'],
  allOf: [
    {
      if: {
        properties: {
          has_premium: {
            const: 'yes',
          },
        },
        required: ['has_premium'],
      },
      then: {
        required: ['premium_id'],
      },
      else: {
        properties: {
          premium_id: false,
        },
      },
    },
  ],
};

If you want a JSON Schema with just the quantity field, pass the following config:

const { schema, warnings } = modify(schemaTickets, {
  pick: ['quantity'],
});

Which will return you the schema:

{
  properties: {
    quantity: {
      title: 'Quantity',
      type: 'integer',
    }
  },
  'x-jsf-order': ['quantity'],
  allOf: undefined
};

Other features:

  • When picked fields have conditional fields, they are also included and it's included in the warnings.
  • NOT done:
    • Pick nested fields
    • Ignore conditionals with missing fields

@danielcardoso5
Copy link
Collaborator

Hey @sandrina-p , I'll review this one tomorrow morning!

src/modify.js Outdated Show resolved Hide resolved
src/modify.js Show resolved Hide resolved
src/modify.js Outdated Show resolved Hide resolved
src/modify.js Outdated Show resolved Hide resolved
src/modify.js Outdated Show resolved Hide resolved
src/modify.js Outdated Show resolved Hide resolved
src/modify.js Outdated Show resolved Hide resolved
src/modify.js Outdated Show resolved Hide resolved
@sandrina-p
Copy link
Collaborator Author

@danielcardoso5 Ready for a new review :D

danielcardoso5
danielcardoso5 previously approved these changes Jul 18, 2024
Copy link
Collaborator

@danielcardoso5 danielcardoso5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good @sandrina-p! Thank you for the added comments re: fieldsets ✨

src/modify.js Show resolved Hide resolved
src/modify.js Outdated Show resolved Hide resolved
@sandrina-p sandrina-p force-pushed the pbyr-1371-jsf-modify-module-allow-picking-fields branch 2 times, most recently from f24214d to 5c7b88d Compare July 24, 2024 15:59
src/modify.js Outdated Show resolved Hide resolved
danielcardoso5
danielcardoso5 previously approved these changes Jul 25, 2024
package.json Outdated Show resolved Hide resolved
danielcardoso5
danielcardoso5 previously approved these changes Jul 25, 2024
@sandrina-p sandrina-p force-pushed the pbyr-1371-jsf-modify-module-allow-picking-fields branch from c8cc064 to a1ddaff Compare July 25, 2024 16:02
@sandrina-p sandrina-p merged commit 2e04402 into main Jul 25, 2024
3 checks passed
@sandrina-p sandrina-p deleted the pbyr-1371-jsf-modify-module-allow-picking-fields branch July 25, 2024 16:30
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.

2 participants