Skip to content

Commit

Permalink
Merge pull request hyperledger-archives#431 from sstone1/master
Browse files Browse the repository at this point in the history
Add namespaces option to LoopBack connector & REST server
  • Loading branch information
Simon Stone authored Mar 12, 2017
2 parents 6f58630 + 21a1e27 commit f74ccca
Show file tree
Hide file tree
Showing 20 changed files with 1,652 additions and 1,502 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ deploy:
script: ./.travis/deploy.sh
skip_cleanup: true
on:
all_branches: true
branch: master
cache: false
sudo: required
notifications:
Expand Down
16 changes: 0 additions & 16 deletions packages/composer-cli/.travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions packages/composer-common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ module.exports.FSConnectionProfileStore = require('./lib/fsconnectionprofilestor
module.exports.Globalize = require('./lib/globalize');
module.exports.Introspector = require('./lib/introspect/introspector');
module.exports.Logger = require('./lib/log/logger');
module.exports.LoopbackVisitor = require('./lib/codegen/fromcto/loopback/loopbackvisitor');
module.exports.ModelFile = require('./lib/introspect/modelfile');
module.exports.ModelManager = require('./lib/modelmanager');
module.exports.ParticipantDeclaration = require('./lib/introspect/participantdeclaration');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ function loopbackify(fqn) {
*/
class LoopbackVisitor {

/**
* Constructor.
* @param {boolean} [namespaces] - whether or not namespaces should be used.
*/
constructor(namespaces) {
this.namespaces = !!namespaces;
}

/**
* Visitor design pattern
* @param {Object} thing - the object being visited
Expand Down Expand Up @@ -145,12 +153,13 @@ class LoopbackVisitor {

// If this is the first declaration, then we are building a schema for this asset.
let jsonSchema = {};
let name = this.namespaces ? assetDeclaration.getFullyQualifiedName() : assetDeclaration.getName();
if (parameters.first) {
jsonSchema = {
$first: true,
name: loopbackify(assetDeclaration.getFullyQualifiedName()),
name: loopbackify(name),
description: `An asset named ${assetDeclaration.getName()}`,
plural: assetDeclaration.getFullyQualifiedName(),
plural: name,
base: 'PersistedModel',
idInjection: false,
options: {
Expand Down Expand Up @@ -187,12 +196,13 @@ class LoopbackVisitor {

// If this is the first declaration, then we are building a schema for this participant.
let jsonSchema = {};
let name = this.namespaces ? participantDeclaration.getFullyQualifiedName() : participantDeclaration.getName();
if (parameters.first) {
jsonSchema = {
$first: true,
name: loopbackify(participantDeclaration.getFullyQualifiedName()),
name: loopbackify(name),
description: `A participant named ${participantDeclaration.getName()}`,
plural: participantDeclaration.getFullyQualifiedName(),
plural: name,
base: 'PersistedModel',
idInjection: false,
options: {
Expand Down Expand Up @@ -229,12 +239,13 @@ class LoopbackVisitor {

// If this is the top declaration, then we are building a schema for this concept.
let jsonSchema = {};
let name = this.namespaces ? conceptDeclaration.getFullyQualifiedName() : conceptDeclaration.getName();
if (parameters.first) {
jsonSchema = {
$first: true,
name: loopbackify(conceptDeclaration.getFullyQualifiedName()),
name: loopbackify(name),
description: `A concept named ${conceptDeclaration.getName()}`,
plural: conceptDeclaration.getFullyQualifiedName(),
plural: name,
// Concepts are not PersistedModel instances as they cannot exist by themselves.
// base: 'PersistedModel',
idInjection: false,
Expand Down Expand Up @@ -271,12 +282,13 @@ class LoopbackVisitor {

// If this is the top declaration, then we are building a schema for this transaction.
let jsonSchema = {};
let name = this.namespaces ? transactionDeclaration.getFullyQualifiedName() : transactionDeclaration.getName();
if (parameters.first) {
jsonSchema = {
$first: true,
name: loopbackify(transactionDeclaration.getFullyQualifiedName()),
name: loopbackify(name),
description: `A transaction named ${transactionDeclaration.getName()}`,
plural: transactionDeclaration.getFullyQualifiedName(),
plural: name,
base: 'PersistedModel',
idInjection: false,
options: {
Expand Down Expand Up @@ -326,7 +338,7 @@ class LoopbackVisitor {

// If no description exists, add it now.
if (!jsonSchema.description) {
jsonSchema.description = `An instance of ${classDeclaration.getFullyQualifiedName()}`;
jsonSchema.description = `An instance of ${classDeclaration.getName()}`;
}

// Every class declaration has a $class property.
Expand All @@ -350,7 +362,8 @@ class LoopbackVisitor {
delete jsonSchema.$first;
let fileContents = JSON.stringify(jsonSchema, null, 4);
if (parameters.fileWriter) {
let fileName = `${classDeclaration.getFullyQualifiedName()}.json`;
let name = this.namespaces ? classDeclaration.getFullyQualifiedName() : classDeclaration.getName();
let fileName = `${name}.json`;
parameters.fileWriter.openFile(fileName);
parameters.fileWriter.write(fileContents);
parameters.fileWriter.closeFile();
Expand Down Expand Up @@ -429,8 +442,9 @@ class LoopbackVisitor {
} else {

// Render the type as JSON Schema.
let typeName = this.namespaces ? field.getFullyQualifiedTypeName() : field.getType();
jsonSchema = {
type: loopbackify(field.getFullyQualifiedTypeName())
type: loopbackify(typeName)
};

// Look up the type of the property.
Expand Down Expand Up @@ -502,7 +516,7 @@ class LoopbackVisitor {
// Create the schema.
let jsonSchema = {
type: 'String',
description: `The identifier of an instance of ${relationshipDeclaration.getFullyQualifiedTypeName()}`,
description: `The identifier of an instance of ${relationshipDeclaration.getName()}`,
required: !relationshipDeclaration.isOptional()
};

Expand Down
Loading

0 comments on commit f74ccca

Please sign in to comment.