Swagger UI is not generated in Jhipster - swagger

I am trying to develop a little bit complex entities, the content of jdl file below. All works fine, but it is not generating the Swagger UI. Kindly advice..
Jhipster Version - 7.0.1
JDL File
application {
config {
baseName myApp,
applicationType monolith,
packageName com.myapp,
authenticationType jwt,
prodDatabaseType postgresql,
clientFramework angular
enableSwaggerCodegen true
}
entities *
}
// One to One
entity Product { name String }
entity Origin { name String}
relationship OneToOne { Product to Origin }
// Many to One
entity Rating { name String }
entity Movie { name String }
relationship ManyToOne { Rating to Movie }
// One to Many
entity Customer { name String }
entity Address { name String }
relationship OneToMany { Customer to Address }
// Many to Many
entity Car { name String }
entity Owner { name String }
relationship ManyToMany { Car to Owner }
Steps to reproduce
jhipster jdl above_jdl.jdl
./mvnw. --> App is running, but there is no Swagger UI for above entities.

I used a JDL similar to yours, without the enableSwaggerCodegen line and it works fine for me.
application {
config {
baseName myApp
applicationType monolith
packageName com.myapp
authenticationType jwt
prodDatabaseType postgresql
clientFramework angular
}
entities *
}
// One to One
entity Product { name String }
entity Origin { name String}
relationship OneToOne { Product to Origin }
// Many to One
entity Rating { name String }
entity Movie { name String }
relationship ManyToOne { Rating to Movie }
// One to Many
entity Customer { name String }
entity Address { name String }
relationship OneToMany { Customer to Address }
// Many to Many
entity Car { name String }
entity Owner { name String }
relationship ManyToMany { Car to Owner }

When using the swaggerCodegen option there are multiple api specs. You must select default to see the spec for the generated entities. If you select openapi (as in your screenshot) you see nothing as the generated spec is empty.

Related

Grails 3 domain class composition

With Grails 3.2.5, hibernate 5.1.2 core.
I have a legacy database that has several clobs in a table. In order to avoid eager fetching, in earlier versions of Grails I defined a domain class that contained only those clobs in order to make them accessed via an (apparent) association which could then be lazily fetched. A sketch of the setup:
class Comment {
String someField // eager
CommentText cmntText // lazy
static mapping = {
id column: 'COMMENT_ID', generator:'sequence', params:[sequence:'cmnt_seq']
}
In a separate domain class file:
class CommentText {
String userComment
static mapping = {
table 'COMMENT'
id generator:'assigned'
userComment sqlType:'clob'
}
As noted, clob column 'user_comment' exists in the single table 'COMMENT'.
In 3.2.5, when doing this I get an error that column 'comment_text_id' is not defined in table 'comment'. This didn't use to be the case, nor should the field have to exist.
On a similar note, in another case I define a composite domain class (a class defined in the same file as the actual domain class). In this case too I get an error about a missing id:
class A {
B b
}
class B {
String someField
}
In this case I get an error saying that field b_id is not in table 'A'. But - it's supposed to be embedded composition, it should not be there.
I'm building within Intellij if that is relevant.
With GORM 6.1 this is now possible with a single domain class
import grails.gorm.hibernate.annotation.ManagedEntity
import static grails.gorm.hibernate.mapping.MappingBuilder.*
#ManagedEntity
class Comment {
String someField
String userComment
static constraints = {
}
static final mapping = orm {
id {
generator("sequence")
params(sequence:'cmnt_seq')
}
userComment = property {
lazy(true)
column {
sqlType 'clob'
}
}
}
}

Grails: Multiple Relationships between same two Objects

How do I define a relationship like the following:
A person can belong to many projects. A person can be the technical contact for a project or, they can be the business contact for a project or they can be both. If the person gets deleted the project doesn't get deleted. If a project gets deleted the person doesn't get deleted.
class Project {
String name
Person technicalContact
Person businessContact
static constraints = {
}
}
class Person {
String firstName
String lastName
String email
String phone
String department
static constraints = {
}
}
You can have 2 one-to-many in one table like this
class Project {
String name
}
class Person {
String firstName
String lastName
String email
String phone
String department
static hasMany = [technicalContactForProjects: Project ,
businessContactForProjects: Project
]
}
Grails will automatically make 2 relation table from that 2 hasMany, so you can delete its relation without delete the actual person or project.

Grails many to many using a third 'join' class

I read that a m:m relationship often means there is a third class that isn't yet required. So I have m:m on User and Project, and I created a third domain class, ProjectMembership
The three domains are as follows (minimized for illustration purposes):
User
class User {
String name
static hasMany = [projectMemberships : ProjectMembership]
}
Project Membership
class ProjectMembership {
static constraints = {
}
static belongsTo = [user:User, project:Project]
}
Project:
class Project {
String name
static hasMany = [projectMemberships : ProjectMembership]
static constraints = {
}
}
If I have the ID of the user, how can I get a list of Project objects that they are assigned to?
There are a handful of ways - here are a couple:
def user = User.get(userId)
ProjectMembership.findAllByUser(user).collect { it.project }
or to avoid the query for the User:
ProjectMembership.withCriteria {
user {
eq('id', userId)
}
}.collect { it.project }
Be wary of queries that'll return large result sets - you'll end up with a huge in-memory list of project objects.

Grails - exception on one-to-one association

I'm having problems with validating the domain classes. I have two domains associated by one-to-one relationship:
class AssemblyForm {
Measures measures
static hasOne = [measures: Measures]
}
class Measures {
AssemblyForm assemblyForm
}
Now I'm binding and creating them in controller and service:
// controller
class AssemblyFormController {
def save() {
AssemblyForm assemblyFormInstance = new AssemblyForm()
assemblyFormInstance.measures = measures
assemblyFormService.save(assemblyFormInstance)
}
}
// service
class AssemblyFormService {
public AssemblyForm save(AssemblyForm assemblyForm) {
try {
assemblyForm.save()
} catch (Throwable t) {
}
return assemblyForm
}
}
Now I would expect assemblyForm entity not to be save in database if its association has error. But the fact is, when Measures entity has some errors, the AssemblyForm is persisted to database while the Measures entity isn't. Am I doing something wrong or this is standard behaviour and I should check the associated entity before saving? Thank you.
Regards,
Lojza

Bidirectional One-To-One

I have two domain classes:
class Contract {
String refNo
}
class Attachment {
byte[] data
String mimeType
String fileName
}
How can I set up the relationships so that I have both contractInstance.attachment and attachmentInstance.contract? I think this is bidirectional one-to-one but I'm not sure (one Contract has to have exactly one Attachment)...
class Contract {
Attachment attachment
}
class Attachment {
static belongsTo = [contract: Contract]
}
This define a 1-to-1 relationship between the two, with Contract being the owner of the relationship. This means that if you save/delete a Contract the save/delete will cascade to the Attachment, but the inverse is not true.
Wouldn't this work:
class Contract {
Attachment attachment
}
class Attachment {
Contract contract
}

Resources