question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

feature: assertions

See original GitHub issue

Request for comments

This feature request is not yet actionable. We need to collect some feedback first.


Is your feature request related to a problem? Please describe. We need a generic rules to be used in cases which our other built-in rules do not cover.

Describe the solution you’d like I’d like to have a set of built-in rules which can be configured to enforce different generic usecases:

  • enum to enforce a value to be among set of predefined values
  • pattern - to enforce a value to match a regex
  • casing - to enforce specific casing style (camelCase, kebab-case, snake_case, PascalCase)
  • mutuallyExclusive - to mark some properties as mutually exclusive (a or b but not a and b together)
  • defined/undefined/nonEmpty
  • length - to enforce length of specific array or string
  • sortOrder - to enforce sort order in array of strings or array of objects (collection)

Example usage:

lint:
  rules:
    enforcements: # I would like a better suggestion here
      - on: SecuritySchema.type
        description: Only API key authorization is allowed
        severity: error
        enum:
          - apiKey
      - on: 'MediaTypeMap.$keys'
          enum:
          - apiKey
        - on: MediaTypeMap.$keys
          description: Only application/json can be used
          enum:
            - 'application/json'
    nonEmpty:
      description: Schema title and description should be non-empty
      locations:
        - on: Schema.description
        - on: Schema.title

Additional context none

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
jacobatorcommented, Nov 1, 2021

I like per-key approach better (allowing “on” to be an array makes it even better)

1reaction
slavikbezcommented, Nov 2, 2021

Do you see any issues with the suggested format that can complicate the UI in the future.

Depending on the selected format the UI will be different. In the original case we’re grouping by node type and I see flow in the UI like the following: (you may think of chain items as form controls):

select node type(s) -> select rule(s) -> provide rule(s) values -> severity -> description -> etc.

In the alternative case we’re grouping by rule and then pull in node types, so in the UI selecting rule should go before selecting node type:

select rule(s) -> select node type(s) -> provide rule(s) values -> severity -> description -> etc.

Also, what do you think about enforcements approach vs alternative per-rule approach?

I prefer the enforcements approach. For me it’s more naturally when you take a node and then describe a rule for it, not vice versa. Other benefits from it what I see so far are:

  1. Easier to generate code for the rule. For example this configuration

     - on: # on can be an array too
           - Schema.description
           - Schema.title
         nonEmpty: true
         regex: '/.$/' # we can also apply also other enforcements
         description: Schema description and title should be non-empty and should end with a dot.
    

    will result in 4 different rules:

    • schema-description-non-empty
    • schema-description-regex
    • schema-title-non-empty
    • schema-title-regex
  2. With more atomic rules we will get more granularity for severity and error messages

Read more comments on GitHub >

github_iconTop Results From Across the Web

Assertion (software development) - Wikipedia
In computer programming, specifically when using the imperative programming paradigm, an assertion is a predicate (a Boolean-valued function over the state ...
Read more >
Assertions - JavaScript - MDN Web Docs
Assertions include boundaries, which indicate the beginnings and endings of lines and words, and other patterns indicating in some way that a match...
Read more >
Programming With Assertions - Oracle Help Center
An assertion is a statement in the Java TM programming language that ... We enhanced Throwable with the getStackTrace method to provide this...
Read more >
Getting started with Assertions | Functional Testing - SoapUI
Lets look at how the Assertion functionality of the Sampler TestSteps are used to validate the incoming response or request received by the...
Read more >
Assert feature — oneAPI DPC++ Compiler documentation
This document describes the design of supporting assertions within SYCL device ... Abort host application when assert function is called and print a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found