Tyk-sync installation and publishing

Hi, Im trying to publish API definitions from a Git repo to a Tyk Dashboard using tyk-sync. I have the api definition in OAS format, does tyk-sync support OAS? would the publish process be same as mentioned in Tyk Sync? and if not how do I convert OAS to tyk-sync compatible api to store in gitlab, so that it can be published to dashboard using tyk-sync.

@deepthi.ar Have you imported your OAS format into Tyk yet and run the dump command?

If I am not wrong, we have a neat trick where we added a is_oas field to the API definition to check if it’s version 3 OAS and then added the Tyk specific OAS schema to handle all the OAS stuff

{
  "api_definition"{
    ...
    "is_oas": true,
    ...
  },
  "oas"": {...}
}

So you should be able to treat it like a normal API definition and Tyk would handle the rest.

{
  "type": "apidef",
  "files": [
    {
      "file": "api-72a21831f0d74eb651a77cae4a880ab2.json",
      "oas": {}
    },

Thank you, This worked out for me like a charm. I was wondering if .tyk.json file supports “type”:“oas”.

Additionally, I wanted to know if there is a way to convert OAS to CRD for tyk operator to use it.

Yes it does. Here is a sample.

{
  "type": "oas",
  "files": [
    {
      "file": "./oas.v2.api.json",
      "api_id": "specify_api_definition_id",
      "db_id": "database_base_id(which is usually the `id` field in the api definition)",
      "org_id": "global",
      "oas": {
        "override_target": "https://upstream_path",
        "override_listen_path": "/oasv2/",
        "strip_listen_path": true,
        "version_name": "2.0.0"
      }
    },
    {
      "file": "./oas.v3.api.json",
      "org_id": "global",
      "oas": {
        "override_target": "https://upstream_path",
        "override_listen_path": "/oasv3/",
        "version_name": "Default"
      }
    }
  ],
  "policies": []
}

The version and the org_id are required properties.

I don’t know about this.

@carol Any ideas?

Thank you so much, this helps!

How do I mention the version here?
When I use type:apidef, and is_oas as false, its imported as HTTP API, but I dont see the paths reflect in the endpoint designer tab. How can I make the paths reflect in endpoint designer.

1 Like

@Olu I’ve tried setting version info in a bunch of ways and places, and I’m getting this error:

{
    "error": "Version information not found"
}

I tried adding oas.version_name as per your advice. I also have version info in my apidef.json in x-tyk-api-gateway.version_data. Neither seem to be setting API definition version properly.

After looking into this further we found that between Tyk Sync 1.3.0 and 1.4.0 our API definitions no longer worked. We’re looking to move to Tyk Operator as soon as it supports OAS, so we’re not looking to spend much more energy on TYk Sync.

You can specify a version if you are using apidef. It is only used when oas is used as the type.

What are you trying to do? Publish, dump or sync?

Since it’s an OAS API, you need to specify oas as the type. apidef is reserved for Tyk API definition schema.

Maybe the dashboard import swagger API is what you are interested in.

I don’t think you should have the x-tyk-api-gateway in the api definition. It would potentially cause the error you are seeing.

Also what are you trying to do, an import or sync?

I believe sync can only import, convert or publish your OAS to Tyk Definitions. I don’t think syncing capability that apidef has is present in the oas type.

If I am not wrong there should be a classic Tyk definition created along side the OAS v3 spec when it is imported. I believe that is what you need to sync

@tombuchaillot could you chip in here

Trying to publish. Is it allowed to mention version only when oas is used as type? and not apidef?

The version is only used when the type specified is oas. Since Sync is open source, I was able to confirm this from the source code. The only place where OAS.VersionName is used is within the fectAPIDefinitionFromOAI (import oas) function

Thank you, this helps!