Git Product home page Git Product logo

Comments (2)

tatomyr avatar tatomyr commented on June 18, 2024

This is interesting.

Schema could contain other schemas, and in your examples, you might be referring to a nested schema.
If you aren't using the where clause, it propagates further down the nested schemas.
The problem here is that whenever you use the where, it stops at the first Schema level it encounters after Response (which, in your case, doesn't contain an enum). The behaviour originates from the behaviour of nested visitors in Redocly CLI.

I don't think we will change the behaviour as it will change how the existing rules work (it might impact other users' rules). I have to think about this more.

As a workaround, you can try writing a custom rule through a plugin for that case. However, it requires some knowledge of JavaScript. I'm not sure it will be easy because the default behaviour will likely be the same because of how the nested visitors work.

A different workaround might be adding another level of the where funnel:

  rule/no-enums-in-responses:
    where:
      - subject:
          type: Response
        assertions:
          defined: true
      - subject: 
          type: SchemaProperties # <-- this ensures we bypass the first level of Schema and check only on the 2nd level 
        assertions: 
          defined: true
        
    subject:
      type: Schema
    assertions:
      disallowed: 
        -  enum

Please keep in mind that the rule will only check for enums in the first Schema inside of the first SchemaProperties.

Let me know if that helps.

from redocly-cli.

samanthawritescode avatar samanthawritescode commented on June 18, 2024

Hey, thank you for the response!

I'm getting by with just blocking enum everywhere and adding exceptions for enums in requests via the redocly ignore file. And I think, for now, it's enough to know that this isn't possible really out of the box.

FWIW my motivation here is that enums in responses are risky from a breaking-changes perspective, but they're not as risky when they're in requests (adding to an enum is a breaking change in a response, but adding to a enum in a request is not). I would expect that it's not uncommon for APIs to have different expectations for schemas in requests vs. responses.

from redocly-cli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.