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

Allow to pass custom spec -> definition for API entity #74

Open
HolmesInc opened this issue Sep 5, 2023 · 1 comment
Open

Allow to pass custom spec -> definition for API entity #74

HolmesInc opened this issue Sep 5, 2023 · 1 comment

Comments

@HolmesInc
Copy link

Describe Request:

I would like to pass custom definitions (like Kafka topics) to a catalog-info API entity definition but because of hardcoded validator rule it's impossible to do that and pass validation.
Could you please add the possibility to pass definition options?

Examples:

apiVersion: backstage.io/v1alpha1
kind: API
metadata:
  namespace: my-namespace
  name: api-name
  annotations:
    gitlab.com/project-id: '12345678'
spec:
  type: api-type
  owner: group:owner-group
  lifecycle: experimental
  definition:
    $topic: topic.area.name.1

Validation of this catalog info will fail because of hardcoded tule here:

function modifyPlaceholders(obj) {
  for (const k in obj) {
    if (typeof obj[k] === 'object') {
      try {
        if (obj[k].$text || obj[k].$openapi || obj[k].$asyncapi) {
          obj[k] = 'DUMMY TEXT';
          return;
        }
      } catch (e) {
        throw new Error(
          `Placeholder with name '${k}' is empty. Please remove it or populate it.`,
        );
      }
      modifyPlaceholders(obj[k]);
    }
  }
}

But with the following update, it'll pass:

function modifyPlaceholders(obj, condition) {
  for (const k in obj) {
    if (typeof obj[k] === 'object') {
      try {
        for (const c of condition) {
          if (obj[k][c]) {
            obj[k] = 'DUMMY TEXT';
            return;
          }
        }
      } catch (e) {
        throw new Error(
          `Placeholder with name '${k}' is empty. Please remove it or populate it.`,
        );
      }
      modifyPlaceholders(obj[k], condition);
    }
  }
}

Where const condition = ['$text', '$openapi', '$asyncapi', '$topic']

Supporting Documentation Links:

https://github.com/RoadieHQ/roadie-backstage-plugins/blob/0b7f60228b6de7c7d0baa5033aff6b105d258d5b/utils/roadie-backstage-entity-validator/src/validator.js#L39C1-L55C2

@Xantier
Copy link
Contributor

Xantier commented Sep 5, 2023

Thanks! Yeah, that sounds like a good idea. Looking forward to the PR

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

2 participants