diff --git a/src/model.ts b/src/model.ts index b4d1419..f52f468 100644 --- a/src/model.ts +++ b/src/model.ts @@ -685,9 +685,14 @@ export class JSORMBase { } static url(id?: string | number): string { - const endpoint = this.endpoint || `/${this.jsonapiType}` + const isIri = (id && typeof id === 'string' && id.startsWith('/')) + const endpoint = (isIri) ? id : (this.endpoint || `/${this.jsonapiType}`) let base = `${this.fullBasePath()}${endpoint}` + if (isIri) { + return base; + } + if (id) { base = `${base}/${id}` } diff --git a/test/unit/model.test.ts b/test/unit/model.test.ts index a4a2a54..46708eb 100644 --- a/test/unit/model.test.ts +++ b/test/unit/model.test.ts @@ -1391,6 +1391,18 @@ describe("Model", () => { "http://base.com/namespace/v1/testtype/testId" ) }) + + it("should use IRI as resource path", () => { + class DefaultBaseUrl extends ApplicationRecord { + static baseUrl: string = "http://base.com" + static apiNamespace: string = "/namespace/v1" + static jsonapiType: string = "testtype" + } + + expect(DefaultBaseUrl.url("/testtype/testId")).to.eq( + "http://base.com/namespace/v1/testtype/testId" + ) + }) }) context("Base URL path generation is overridden", () => {